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

Function array_get_slice

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

* array_get_slice : * This routine takes an array and a range of indices (upperIndx and * lowerIndx), creates a new array structure for the referred elements * and returns a pointer to it. * * This handles both ordinary varlena arrays and fixed-length arrays. * * Inputs: * arraydatum: the array object (mustn't be NULL) * nSubscripts: number of subscripts supplied (must be same

Source from the content-addressed store, hash-verified

2041 * even when nSubscripts is less. These are generally just temporaries.
2042 */
2043Datum
2044array_get_slice(Datum arraydatum,
2045 int nSubscripts,
2046 int *upperIndx,
2047 int *lowerIndx,
2048 bool *upperProvided,
2049 bool *lowerProvided,
2050 int arraytyplen,
2051 int elmlen,
2052 bool elmbyval,
2053 char elmalign)
2054{
2055 ArrayType *array;
2056 ArrayType *newarray;
2057 int i,
2058 ndim,
2059 *dim,
2060 *lb,
2061 *newlb;
2062 int fixedDim[1],
2063 fixedLb[1];
2064 Oid elemtype;
2065 char *arraydataptr;
2066 bits8 *arraynullsptr;
2067 int32 dataoffset;
2068 int bytes,
2069 span[MAXDIM];
2070
2071 if (arraytyplen > 0)
2072 {
2073 /*
2074 * fixed-length arrays -- currently, cannot slice these because parser
2075 * labels output as being of the fixed-length array type! Code below
2076 * shows how we could support it if the parser were changed to label
2077 * output as a suitable varlena array type.
2078 */
2079 ereport(ERROR,
2080 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2081 errmsg("slices of fixed-length arrays not implemented")));
2082
2083 /*
2084 * fixed-length arrays -- these are assumed to be 1-d, 0-based
2085 *
2086 * XXX where would we get the correct ELEMTYPE from?
2087 */
2088 ndim = 1;
2089 fixedDim[0] = arraytyplen / elmlen;
2090 fixedLb[0] = 0;
2091 dim = fixedDim;
2092 lb = fixedLb;
2093 elemtype = InvalidOid; /* XXX */
2094 arraydataptr = (char *) DatumGetPointer(arraydatum);
2095 arraynullsptr = NULL;
2096 }
2097 else
2098 {
2099 /* detoast input array if necessary */
2100 array = DatumGetArrayTypeP(arraydatum);

Callers 3

trim_arrayFunction · 0.85

Calls 8

construct_empty_arrayFunction · 0.85
mda_get_rangeFunction · 0.85
array_slice_sizeFunction · 0.85
ArrayGetNItemsFunction · 0.85
array_extract_sliceFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
palloc0Function · 0.50

Tested by

no test coverage detected