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

Function array_agg_array_combine

src/backend/utils/adt/array_userfuncs.c:1169–1318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1167}
1168
1169Datum
1170array_agg_array_combine(PG_FUNCTION_ARGS)
1171{
1172 ArrayBuildStateArr *state1;
1173 ArrayBuildStateArr *state2;
1174 MemoryContext agg_context;
1175 MemoryContext old_context;
1176
1177 if (!AggCheckCallContext(fcinfo, &agg_context))
1178 elog(ERROR, "aggregate function called in non-aggregate context");
1179
1180 state1 = PG_ARGISNULL(0) ? NULL : (ArrayBuildStateArr *) PG_GETARG_POINTER(0);
1181 state2 = PG_ARGISNULL(1) ? NULL : (ArrayBuildStateArr *) PG_GETARG_POINTER(1);
1182
1183 if (state2 == NULL)
1184 {
1185 /*
1186 * NULL state2 is easy, just return state1, which we know is already
1187 * in the agg_context
1188 */
1189 if (state1 == NULL)
1190 PG_RETURN_NULL();
1191 PG_RETURN_POINTER(state1);
1192 }
1193
1194 if (state1 == NULL)
1195 {
1196 /* We must copy state2's data into the agg_context */
1197 old_context = MemoryContextSwitchTo(agg_context);
1198
1199 state1 = initArrayResultArr(state2->array_type, InvalidOid,
1200 agg_context, false);
1201
1202 state1->abytes = state2->abytes;
1203 state1->data = (char *) palloc(state1->abytes);
1204
1205 if (state2->nullbitmap)
1206 {
1207 int size = (state2->aitems + 7) / 8;
1208
1209 state1->nullbitmap = (bits8 *) palloc(size);
1210 memcpy(state1->nullbitmap, state2->nullbitmap, size);
1211 }
1212
1213 memcpy(state1->data, state2->data, state2->nbytes);
1214 state1->nbytes = state2->nbytes;
1215 state1->aitems = state2->aitems;
1216 state1->nitems = state2->nitems;
1217 state1->ndims = state2->ndims;
1218 memcpy(state1->dims, state2->dims, sizeof(state2->dims));
1219 memcpy(state1->lbs, state2->lbs, sizeof(state2->lbs));
1220 state1->array_type = state2->array_type;
1221 state1->element_type = state2->element_type;
1222
1223 MemoryContextSwitchTo(old_context);
1224
1225 PG_RETURN_POINTER(state1);
1226 }

Callers

nothing calls this directly

Calls 8

AggCheckCallContextFunction · 0.85
MemoryContextSwitchToFunction · 0.85
initArrayResultArrFunction · 0.85
array_bitmap_copyFunction · 0.85
pallocFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50
repallocFunction · 0.50

Tested by

no test coverage detected