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

Function array_iterate

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

* Iterate through the array referenced by 'iterator'. * * As long as there is another element (or slice), return it into * *value / *isnull, and return true. Return false when no more data. */

Source from the content-addressed store, hash-verified

4563 * *value / *isnull, and return true. Return false when no more data.
4564 */
4565bool
4566array_iterate(ArrayIterator iterator, Datum *value, bool *isnull)
4567{
4568 /* Done if we have reached the end of the array */
4569 if (iterator->current_item >= iterator->nitems)
4570 return false;
4571
4572 if (iterator->slice_ndim == 0)
4573 {
4574 /*
4575 * Scalar case: return one element.
4576 */
4577 if (array_get_isnull(iterator->nullbitmap, iterator->current_item++))
4578 {
4579 *isnull = true;
4580 *value = (Datum) 0;
4581 }
4582 else
4583 {
4584 /* non-NULL, so fetch the individual Datum to return */
4585 char *p = iterator->data_ptr;
4586
4587 *isnull = false;
4588 *value = fetch_att(p, iterator->typbyval, iterator->typlen);
4589
4590 /* Move our data pointer forward to the next element */
4591 p = att_addlength_pointer(p, iterator->typlen, p);
4592 p = (char *) att_align_nominal(p, iterator->typalign);
4593 iterator->data_ptr = p;
4594 }
4595 }
4596 else
4597 {
4598 /*
4599 * Slice case: build and return an array of the requested size.
4600 */
4601 ArrayType *result;
4602 Datum *values = iterator->slice_values;
4603 bool *nulls = iterator->slice_nulls;
4604 char *p = iterator->data_ptr;
4605 int i;
4606
4607 for (i = 0; i < iterator->slice_len; i++)
4608 {
4609 if (array_get_isnull(iterator->nullbitmap,
4610 iterator->current_item++))
4611 {
4612 nulls[i] = true;
4613 values[i] = (Datum) 0;
4614 }
4615 else
4616 {
4617 nulls[i] = false;
4618 values[i] = fetch_att(p, iterator->typbyval, iterator->typlen);
4619
4620 /* Move our data pointer forward to the next element */
4621 p = att_addlength_pointer(p, iterator->typlen, p);
4622 p = (char *) att_align_nominal(p, iterator->typalign);

Callers 6

ArrayIterateMethod · 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 2

array_get_isnullFunction · 0.85
construct_md_arrayFunction · 0.85

Tested by

no test coverage detected