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

Function array_get_element_expanded

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

* Implementation of array_get_element() for an expanded array */

Source from the content-addressed store, hash-verified

1932 * Implementation of array_get_element() for an expanded array
1933 */
1934static Datum
1935array_get_element_expanded(Datum arraydatum,
1936 int nSubscripts, int *indx,
1937 int arraytyplen,
1938 int elmlen, bool elmbyval, char elmalign,
1939 bool *isNull)
1940{
1941 ExpandedArrayHeader *eah;
1942 int i,
1943 ndim,
1944 *dim,
1945 *lb,
1946 offset;
1947 Datum *dvalues;
1948 bool *dnulls;
1949
1950 eah = (ExpandedArrayHeader *) DatumGetEOHP(arraydatum);
1951 Assert(eah->ea_magic == EA_MAGIC);
1952
1953 /* sanity-check caller's info against object */
1954 Assert(arraytyplen == -1);
1955 Assert(elmlen == eah->typlen);
1956 Assert(elmbyval == eah->typbyval);
1957 Assert(elmalign == eah->typalign);
1958
1959 ndim = eah->ndims;
1960 dim = eah->dims;
1961 lb = eah->lbound;
1962
1963 /*
1964 * Return NULL for invalid subscript
1965 */
1966 if (ndim != nSubscripts || ndim <= 0 || ndim > MAXDIM)
1967 {
1968 *isNull = true;
1969 return (Datum) 0;
1970 }
1971 for (i = 0; i < ndim; i++)
1972 {
1973 if (indx[i] < lb[i] || indx[i] >= (dim[i] + lb[i]))
1974 {
1975 *isNull = true;
1976 return (Datum) 0;
1977 }
1978 }
1979
1980 /*
1981 * Calculate the element number
1982 */
1983 offset = ArrayGetOffset(nSubscripts, dim, lb, indx);
1984
1985 /*
1986 * Deconstruct array if we didn't already. Note that we apply this even
1987 * if the input is nominally read-only: it should be safe enough.
1988 */
1989 deconstruct_expanded_array(eah);
1990
1991 dvalues = eah->dvalues;

Callers 1

array_get_elementFunction · 0.85

Calls 3

DatumGetEOHPFunction · 0.85
ArrayGetOffsetFunction · 0.85

Tested by

no test coverage detected