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

Function populate_array

src/backend/utils/adt/jsonfuncs.c:2832–2877  ·  view source on GitHub ↗

recursively populate an array from json/jsonb */

Source from the content-addressed store, hash-verified

2830
2831/* recursively populate an array from json/jsonb */
2832static Datum
2833populate_array(ArrayIOData *aio,
2834 const char *colname,
2835 MemoryContext mcxt,
2836 JsValue *jsv)
2837{
2838 PopulateArrayContext ctx;
2839 Datum result;
2840 int *lbs;
2841 int i;
2842
2843 ctx.aio = aio;
2844 ctx.mcxt = mcxt;
2845 ctx.acxt = CurrentMemoryContext;
2846 ctx.astate = initArrayResult(aio->element_type, ctx.acxt, true);
2847 ctx.colname = colname;
2848 ctx.ndims = 0; /* unknown yet */
2849 ctx.dims = NULL;
2850 ctx.sizes = NULL;
2851
2852 if (jsv->is_json)
2853 populate_array_json(&ctx, jsv->val.json.str,
2854 jsv->val.json.len >= 0 ? jsv->val.json.len
2855 : strlen(jsv->val.json.str));
2856 else
2857 {
2858 populate_array_dim_jsonb(&ctx, jsv->val.jsonb, 1);
2859 ctx.dims[0] = ctx.sizes[0];
2860 }
2861
2862 Assert(ctx.ndims > 0);
2863
2864 lbs = palloc(sizeof(int) * ctx.ndims);
2865
2866 for (i = 0; i < ctx.ndims; i++)
2867 lbs[i] = 1;
2868
2869 result = makeMdArrayResult(ctx.astate, ctx.ndims, ctx.dims, lbs,
2870 ctx.acxt, true);
2871
2872 pfree(ctx.dims);
2873 pfree(ctx.sizes);
2874 pfree(lbs);
2875
2876 return result;
2877}
2878
2879static void
2880JsValueToJsObject(JsValue *jsv, JsObject *jso)

Callers 1

populate_record_fieldFunction · 0.85

Calls 6

initArrayResultFunction · 0.85
populate_array_jsonFunction · 0.85
populate_array_dim_jsonbFunction · 0.85
makeMdArrayResultFunction · 0.85
pallocFunction · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected