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

Function array_to_jsonb_internal

src/backend/utils/adt/jsonb.c:985–1028  ·  view source on GitHub ↗

* Turn an array into JSON. */

Source from the content-addressed store, hash-verified

983 * Turn an array into JSON.
984 */
985static void
986array_to_jsonb_internal(Datum array, JsonbInState *result)
987{
988 ArrayType *v = DatumGetArrayTypeP(array);
989 Oid element_type = ARR_ELEMTYPE(v);
990 int *dim;
991 int ndim;
992 int nitems;
993 int count = 0;
994 Datum *elements;
995 bool *nulls;
996 int16 typlen;
997 bool typbyval;
998 char typalign;
999 JsonbTypeCategory tcategory;
1000 Oid outfuncoid;
1001
1002 ndim = ARR_NDIM(v);
1003 dim = ARR_DIMS(v);
1004 nitems = ArrayGetNItems(ndim, dim);
1005
1006 if (nitems <= 0)
1007 {
1008 result->res = pushJsonbValue(&result->parseState, WJB_BEGIN_ARRAY, NULL);
1009 result->res = pushJsonbValue(&result->parseState, WJB_END_ARRAY, NULL);
1010 return;
1011 }
1012
1013 get_typlenbyvalalign(element_type,
1014 &typlen, &typbyval, &typalign);
1015
1016 jsonb_categorize_type(element_type,
1017 &tcategory, &outfuncoid);
1018
1019 deconstruct_array(v, element_type, typlen, typbyval,
1020 typalign, &elements, &nulls,
1021 &nitems);
1022
1023 array_dim_to_jsonb(result, 0, ndim, dim, elements, nulls, &count, tcategory,
1024 outfuncoid);
1025
1026 pfree(elements);
1027 pfree(nulls);
1028}
1029
1030/*
1031 * Turn a composite / record into JSON.

Callers 1

datum_to_jsonbFunction · 0.85

Calls 7

ArrayGetNItemsFunction · 0.85
pushJsonbValueFunction · 0.85
get_typlenbyvalalignFunction · 0.85
jsonb_categorize_typeFunction · 0.85
deconstruct_arrayFunction · 0.85
array_dim_to_jsonbFunction · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected