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

Function construct_md_array

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

* construct_md_array --- simple method for constructing an array object * with arbitrary dimensions and possible NULLs * * elems: array of Datum items to become the array contents * nulls: array of is-null flags (can be NULL if no nulls) * ndims: number of dimensions * dims: integer array with size of each dimension * lbs: integer array with lower bound of each dimension * elmtype, e

Source from the content-addressed store, hash-verified

3407 * to hard-wire values if the element type is hard-wired.
3408 */
3409ArrayType *
3410construct_md_array(Datum *elems,
3411 bool *nulls,
3412 int ndims,
3413 int *dims,
3414 int *lbs,
3415 Oid elmtype, int elmlen, bool elmbyval, char elmalign)
3416{
3417 ArrayType *result;
3418 bool hasnulls;
3419 int32 nbytes;
3420 int32 dataoffset;
3421 int i;
3422 int nelems;
3423 bool fixedwidthtype;
3424
3425 if (ndims < 0) /* we do allow zero-dimension arrays */
3426 ereport(ERROR,
3427 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3428 errmsg("invalid number of dimensions: %d", ndims)));
3429 if (ndims > MAXDIM)
3430 ereport(ERROR,
3431 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3432 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
3433 ndims, MAXDIM)));
3434
3435 /* This checks for overflow of the array dimensions */
3436 nelems = ArrayGetNItems(ndims, dims);
3437 ArrayCheckBounds(ndims, dims, lbs);
3438
3439 /* if ndims <= 0 or any dims[i] == 0, return empty array */
3440 if (nelems <= 0)
3441 return construct_empty_array(elmtype);
3442
3443 /* compute required space */
3444 nbytes = 0;
3445
3446 /* fast path for fixed width types */
3447 switch (elmtype)
3448 {
3449 case INT2OID:
3450 case INT4OID:
3451 case INT8OID:
3452 case FLOAT4OID:
3453 case FLOAT8OID:
3454 fixedwidthtype=true;
3455 break;
3456 default:
3457 fixedwidthtype=false;
3458 }
3459 hasnulls = false;
3460 if (fixedwidthtype)
3461 {
3462 nbytes = nelems * elmlen;
3463
3464 /* Still need to handle the possibility of nulls */
3465 if (nulls)
3466 {

Callers 15

ConstructMdArrayTypeMethod · 0.85
hstore_slice_to_arrayFunction · 0.85
hstore_avalsFunction · 0.85
hstore_to_array_internalFunction · 0.85
plpgsql_fulfill_promiseFunction · 0.85
array_set_elementFunction · 0.85
array_set_sliceFunction · 0.85
construct_arrayFunction · 0.85
array_iterateFunction · 0.85
makeMdArrayResultFunction · 0.85

Calls 7

ArrayGetNItemsFunction · 0.85
ArrayCheckBoundsFunction · 0.85
construct_empty_arrayFunction · 0.85
CopyArrayElsFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
palloc0Function · 0.50

Tested by 2

build_test_info_resultFunction · 0.68
build_test_match_resultFunction · 0.68