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

Function array_set_element_expanded

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

* Implementation of array_set_element() for an expanded array * * Note: as with any operation on a read/write expanded object, we must * take pains not to leave the object in a corrupt state if we fail partway * through. */

Source from the content-addressed store, hash-verified

2513 * through.
2514 */
2515static Datum
2516array_set_element_expanded(Datum arraydatum,
2517 int nSubscripts, int *indx,
2518 Datum dataValue, bool isNull,
2519 int arraytyplen,
2520 int elmlen, bool elmbyval, char elmalign)
2521{
2522 ExpandedArrayHeader *eah;
2523 Datum *dvalues;
2524 bool *dnulls;
2525 int i,
2526 ndim,
2527 dim[MAXDIM],
2528 lb[MAXDIM],
2529 offset;
2530 bool dimschanged,
2531 newhasnulls;
2532 int addedbefore,
2533 addedafter;
2534 char *oldValue;
2535
2536 /* Convert to R/W object if not so already */
2537 eah = DatumGetExpandedArray(arraydatum);
2538
2539 /* Sanity-check caller's info against object; we don't use it otherwise */
2540 Assert(arraytyplen == -1);
2541 Assert(elmlen == eah->typlen);
2542 Assert(elmbyval == eah->typbyval);
2543 Assert(elmalign == eah->typalign);
2544
2545 /*
2546 * Copy dimension info into local storage. This allows us to modify the
2547 * dimensions if needed, while not messing up the expanded value if we
2548 * fail partway through.
2549 */
2550 ndim = eah->ndims;
2551 Assert(ndim >= 0 && ndim <= MAXDIM);
2552 memcpy(dim, eah->dims, ndim * sizeof(int));
2553 memcpy(lb, eah->lbound, ndim * sizeof(int));
2554 dimschanged = false;
2555
2556 /*
2557 * if number of dims is zero, i.e. an empty array, create an array with
2558 * nSubscripts dimensions, and set the lower bounds to the supplied
2559 * subscripts.
2560 */
2561 if (ndim == 0)
2562 {
2563 /*
2564 * Allocate adequate space for new dimension info. This is harmless
2565 * if we fail later.
2566 */
2567 Assert(nSubscripts > 0 && nSubscripts <= MAXDIM);
2568 eah->dims = (int *) MemoryContextAllocZero(eah->hdr.eoh_context,
2569 nSubscripts * sizeof(int));
2570 eah->lbound = (int *) MemoryContextAllocZero(eah->hdr.eoh_context,
2571 nSubscripts * sizeof(int));
2572

Callers 1

array_set_elementFunction · 0.85

Calls 14

DatumGetExpandedArrayFunction · 0.85
MemoryContextAllocZeroFunction · 0.85
MemoryContextSwitchToFunction · 0.85
datumCopyFunction · 0.85
pg_sub_s32_overflowFunction · 0.85
pg_add_s32_overflowFunction · 0.85
ArrayGetNItemsFunction · 0.85
ArrayCheckBoundsFunction · 0.85
ArrayGetOffsetFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected