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

Function cube_subset

contrib/cube/cube.c:241–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

239}
240
241Datum
242cube_subset(PG_FUNCTION_ARGS)
243{
244 NDBOX *c = PG_GETARG_NDBOX_P(0);
245 ArrayType *idx = PG_GETARG_ARRAYTYPE_P(1);
246 NDBOX *result;
247 int size,
248 dim,
249 i;
250 int *dx;
251
252 if (array_contains_nulls(idx))
253 ereport(ERROR,
254 (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
255 errmsg("cannot work with arrays containing NULLs")));
256
257 dx = (int32 *) ARR_DATA_PTR(idx);
258
259 dim = ARRNELEMS(idx);
260 if (dim > CUBE_MAX_DIM)
261 ereport(ERROR,
262 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
263 errmsg("array is too long"),
264 errdetail("A cube cannot have more than %d dimensions.",
265 CUBE_MAX_DIM)));
266
267 size = IS_POINT(c) ? POINT_SIZE(dim) : CUBE_SIZE(dim);
268 result = (NDBOX *) palloc0(size);
269 SET_VARSIZE(result, size);
270 SET_DIM(result, dim);
271
272 if (IS_POINT(c))
273 SET_POINT_BIT(result);
274
275 for (i = 0; i < dim; i++)
276 {
277 if ((dx[i] <= 0) || (dx[i] > DIM(c)))
278 ereport(ERROR,
279 (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
280 errmsg("Index out of bounds")));
281 result->x[i] = c->x[dx[i] - 1];
282 if (!IS_POINT(c))
283 result->x[i + dim] = c->x[dx[i] + DIM(c) - 1];
284 }
285
286 PG_FREE_IF_COPY(c, 0);
287 PG_RETURN_NDBOX_P(result);
288}
289
290Datum
291cube_out(PG_FUNCTION_ARGS)

Callers

nothing calls this directly

Calls 5

array_contains_nullsFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errdetailFunction · 0.50
palloc0Function · 0.50

Tested by

no test coverage detected