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

Function array_create_iterator

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

* array_create_iterator --- set up to iterate through an array * * If slice_ndim is zero, we will iterate element-by-element; the returned * datums are of the array's element type. * * If slice_ndim is 1..ARR_NDIM(arr), we will iterate by slices: the * returned datums are of the same array type as 'arr', but of size * equal to the rightmost N dimensions of 'arr'. * * The passed-in array m

Source from the content-addressed store, hash-verified

4484 * The passed-in array must remain valid for the lifetime of the iterator.
4485 */
4486ArrayIterator
4487array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate)
4488{
4489 ArrayIterator iterator = palloc0(sizeof(ArrayIteratorData));
4490
4491 /*
4492 * Sanity-check inputs --- caller should have got this right already
4493 */
4494 Assert(PointerIsValid(arr));
4495 if (slice_ndim < 0 || slice_ndim > ARR_NDIM(arr))
4496 elog(ERROR, "invalid arguments to array_create_iterator");
4497
4498 /*
4499 * Remember basic info about the array and its element type
4500 */
4501 iterator->arr = arr;
4502 iterator->nullbitmap = ARR_NULLBITMAP(arr);
4503 iterator->nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
4504
4505 if (mstate != NULL)
4506 {
4507 Assert(mstate->element_type == ARR_ELEMTYPE(arr));
4508
4509 iterator->typlen = mstate->typlen;
4510 iterator->typbyval = mstate->typbyval;
4511 iterator->typalign = mstate->typalign;
4512 }
4513 else
4514 get_typlenbyvalalign(ARR_ELEMTYPE(arr),
4515 &iterator->typlen,
4516 &iterator->typbyval,
4517 &iterator->typalign);
4518
4519 /*
4520 * Remember the slicing parameters.
4521 */
4522 iterator->slice_ndim = slice_ndim;
4523
4524 if (slice_ndim > 0)
4525 {
4526 /*
4527 * Get pointers into the array's dims and lbound arrays to represent
4528 * the dims/lbound arrays of a slice. These are the same as the
4529 * rightmost N dimensions of the array.
4530 */
4531 iterator->slice_dims = ARR_DIMS(arr) + ARR_NDIM(arr) - slice_ndim;
4532 iterator->slice_lbound = ARR_LBOUND(arr) + ARR_NDIM(arr) - slice_ndim;
4533
4534 /*
4535 * Compute number of elements in a slice.
4536 */
4537 iterator->slice_len = ArrayGetNItems(slice_ndim,
4538 iterator->slice_dims);
4539
4540 /*
4541 * Create workspace for building sub-arrays.
4542 */
4543 iterator->slice_values = (Datum *)

Callers 6

ArrayCreateIteratorMethod · 0.85
exec_stmt_foreach_aFunction · 0.85
array_position_commonFunction · 0.85
array_positionsFunction · 0.85
ora_greatest_leastFunction · 0.85
executeFunction · 0.85

Calls 4

ArrayGetNItemsFunction · 0.85
get_typlenbyvalalignFunction · 0.85
palloc0Function · 0.50
pallocFunction · 0.50

Tested by

no test coverage detected