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

Function cube_a_f8_f8

contrib/cube/cube.c:137–199  ·  view source on GitHub ↗

** Allows the construction of a cube from 2 float[]'s */

Source from the content-addressed store, hash-verified

135** Allows the construction of a cube from 2 float[]'s
136*/
137Datum
138cube_a_f8_f8(PG_FUNCTION_ARGS)
139{
140 ArrayType *ur = PG_GETARG_ARRAYTYPE_P(0);
141 ArrayType *ll = PG_GETARG_ARRAYTYPE_P(1);
142 NDBOX *result;
143 int i;
144 int dim;
145 int size;
146 bool point;
147 double *dur,
148 *dll;
149
150 if (array_contains_nulls(ur) || array_contains_nulls(ll))
151 ereport(ERROR,
152 (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
153 errmsg("cannot work with arrays containing NULLs")));
154
155 dim = ARRNELEMS(ur);
156 if (dim > CUBE_MAX_DIM)
157 ereport(ERROR,
158 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
159 errmsg("can't extend cube"),
160 errdetail("A cube cannot have more than %d dimensions.",
161 CUBE_MAX_DIM)));
162
163 if (ARRNELEMS(ll) != dim)
164 ereport(ERROR,
165 (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
166 errmsg("UR and LL arrays must be of same length")));
167
168 dur = ARRPTR(ur);
169 dll = ARRPTR(ll);
170
171 /* Check if it's a point */
172 point = true;
173 for (i = 0; i < dim; i++)
174 {
175 if (dur[i] != dll[i])
176 {
177 point = false;
178 break;
179 }
180 }
181
182 size = point ? POINT_SIZE(dim) : CUBE_SIZE(dim);
183 result = (NDBOX *) palloc0(size);
184 SET_VARSIZE(result, size);
185 SET_DIM(result, dim);
186
187 for (i = 0; i < dim; i++)
188 result->x[i] = dur[i];
189
190 if (!point)
191 {
192 for (i = 0; i < dim; i++)
193 result->x[i + dim] = dll[i];
194 }

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