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

Function accumArrayResultArr

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

* accumArrayResultArr - accumulate one (more) sub-array for an array result * * astate is working state (can be NULL on first call) * dvalue/disnull represent the new sub-array to append to the array * array_type is the array type (must be a valid varlena array type) * rcontext is where to keep working state */

Source from the content-addressed store, hash-verified

5431 * rcontext is where to keep working state
5432 */
5433ArrayBuildStateArr *
5434accumArrayResultArr(ArrayBuildStateArr *astate,
5435 Datum dvalue, bool disnull,
5436 Oid array_type,
5437 MemoryContext rcontext)
5438{
5439 ArrayType *arg;
5440 MemoryContext oldcontext;
5441 int *dims,
5442 *lbs,
5443 ndims,
5444 nitems,
5445 ndatabytes;
5446 char *data;
5447 int i;
5448
5449 /*
5450 * We disallow accumulating null subarrays. Another plausible definition
5451 * is to ignore them, but callers that want that can just skip calling
5452 * this function.
5453 */
5454 if (disnull)
5455 ereport(ERROR,
5456 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5457 errmsg("cannot accumulate null arrays")));
5458
5459 /* Detoast input array in caller's context */
5460 arg = DatumGetArrayTypeP(dvalue);
5461
5462 if (astate == NULL)
5463 astate = initArrayResultArr(array_type, InvalidOid, rcontext, true);
5464 else
5465 Assert(astate->array_type == array_type);
5466
5467 oldcontext = MemoryContextSwitchTo(astate->mcontext);
5468
5469 /* Collect this input's dimensions */
5470 ndims = ARR_NDIM(arg);
5471 dims = ARR_DIMS(arg);
5472 lbs = ARR_LBOUND(arg);
5473 data = ARR_DATA_PTR(arg);
5474 nitems = ArrayGetNItems(ndims, dims);
5475 ndatabytes = ARR_SIZE(arg) - ARR_DATA_OFFSET(arg);
5476
5477 if (astate->ndims == 0)
5478 {
5479 /* First input; check/save the dimensionality info */
5480
5481 /* Should we allow empty inputs and just produce an empty output? */
5482 if (ndims == 0)
5483 ereport(ERROR,
5484 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5485 errmsg("cannot accumulate empty arrays")));
5486 if (ndims + 1 > MAXDIM)
5487 ereport(ERROR,
5488 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5489 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
5490 ndims + 1, MAXDIM)));

Callers 2

accumArrayResultAnyFunction · 0.85
array_agg_array_transfnFunction · 0.85

Calls 10

initArrayResultArrFunction · 0.85
MemoryContextSwitchToFunction · 0.85
ArrayGetNItemsFunction · 0.85
pg_nextpower2_32Function · 0.85
array_bitmap_copyFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
pallocFunction · 0.50
repallocFunction · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected