MCPcopy Create free account
hub / github.com/apache/cloudberry / makeArrayResultArr

Function makeArrayResultArr

src/backend/utils/adt/arrayfuncs.c:5586–5650  ·  view source on GitHub ↗

* makeArrayResultArr - produce N+1-D final result of accumArrayResultArr * * astate is working state (must not be NULL) * rcontext is where to construct result * release is true if okay to release working state */

Source from the content-addressed store, hash-verified

5584 * release is true if okay to release working state
5585 */
5586Datum
5587makeArrayResultArr(ArrayBuildStateArr *astate,
5588 MemoryContext rcontext,
5589 bool release)
5590{
5591 ArrayType *result;
5592 MemoryContext oldcontext;
5593
5594 /* Build the final array result in rcontext */
5595 oldcontext = MemoryContextSwitchTo(rcontext);
5596
5597 if (astate->ndims == 0)
5598 {
5599 /* No inputs, return empty array */
5600 result = construct_empty_array(astate->element_type);
5601 }
5602 else
5603 {
5604 int dataoffset,
5605 nbytes;
5606
5607 /* Check for overflow of the array dimensions */
5608 (void) ArrayGetNItems(astate->ndims, astate->dims);
5609 ArrayCheckBounds(astate->ndims, astate->dims, astate->lbs);
5610
5611 /* Compute required space */
5612 nbytes = astate->nbytes;
5613 if (astate->nullbitmap != NULL)
5614 {
5615 dataoffset = ARR_OVERHEAD_WITHNULLS(astate->ndims, astate->nitems);
5616 nbytes += dataoffset;
5617 }
5618 else
5619 {
5620 dataoffset = 0;
5621 nbytes += ARR_OVERHEAD_NONULLS(astate->ndims);
5622 }
5623
5624 result = (ArrayType *) palloc0(nbytes);
5625 SET_VARSIZE(result, nbytes);
5626 result->ndim = astate->ndims;
5627 result->dataoffset = dataoffset;
5628 result->elemtype = astate->element_type;
5629
5630 memcpy(ARR_DIMS(result), astate->dims, astate->ndims * sizeof(int));
5631 memcpy(ARR_LBOUND(result), astate->lbs, astate->ndims * sizeof(int));
5632 memcpy(ARR_DATA_PTR(result), astate->data, astate->nbytes);
5633
5634 if (astate->nullbitmap != NULL)
5635 array_bitmap_copy(ARR_NULLBITMAP(result), 0,
5636 astate->nullbitmap, 0,
5637 astate->nitems);
5638 }
5639
5640 MemoryContextSwitchTo(oldcontext);
5641
5642 /* Clean up all the junk */
5643 if (release)

Callers 2

makeArrayResultAnyFunction · 0.85
array_agg_array_finalfnFunction · 0.85

Calls 6

MemoryContextSwitchToFunction · 0.85
construct_empty_arrayFunction · 0.85
ArrayGetNItemsFunction · 0.85
ArrayCheckBoundsFunction · 0.85
array_bitmap_copyFunction · 0.85
palloc0Function · 0.50

Tested by

no test coverage detected