1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
7 */
8
9#include "monetdb_config.h"
10#include "mal.h"
11#include "mal_exception.h"
12
13/*
14 * grouped aggregates
15 */
16static str
17AGGRgrouped(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, const bat *sid,
18 bool skip_nils, bool abort_on_error, int scale, int tp,
19 BAT *(*grpfunc1)(BAT *, BAT *, BAT *, BAT *, int, bool, bool),
20 gdk_return (*grpfunc2)(BAT **, BAT **, BAT *, BAT *, BAT *, BAT *, int, bool, bool, int),
21 BAT *(*quantilefunc)(BAT *, BAT *, BAT *, BAT *, int, double, bool, bool),
22 const bat *quantile,
23 const char *malfunc)
24{
25 BAT *b, *g, *e, *s, *bn = NULL, *cnts, *q = NULL;
26 double qvalue;
27
28 /* exactly one of grpfunc1, grpfunc2 and quantilefunc is non-NULL */
29 assert((grpfunc1 != NULL) + (grpfunc2 != NULL) + (quantilefunc != NULL) == 1);
30
31 /* if retval2 is non-NULL, we must have grpfunc2 */
32 assert(retval2 == NULL || grpfunc2 != NULL);
33 /* only quantiles need a quantile BAT */
34 assert((quantilefunc == NULL) == (quantile == NULL));
35
36 b = BATdescriptor(*bid);
37 g = gid ? BATdescriptor(*gid) : NULL;
38 e = eid ? BATdescriptor(*eid) : NULL;
39 s = sid ? BATdescriptor(*sid) : NULL;
40 q = quantile ? BATdescriptor(*quantile) : NULL;
41
42 if (b == NULL ||
43 (gid != NULL && g == NULL) ||
44 (eid != NULL && e == NULL) ||
45 (sid != NULL && s == NULL) ||
46 (quantile != NULL && q == NULL)) {
47 if (b)
48 BBPunfix(b->batCacheid);
49 if (g)
50 BBPunfix(g->batCacheid);
51 if (e)
52 BBPunfix(e->batCacheid);
53 if (s)
54 BBPunfix(s->batCacheid);
55 if (q)
56 BBPunfix(q->batCacheid);
57 throw(MAL, malfunc, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
58 }
59 if (tp == TYPE_any &&
60 (grpfunc1 == BATgroupmedian ||
61 grpfunc1 == BATgroupmedian_avg ||
62 quantilefunc == BATgroupquantile ||
63 quantilefunc == BATgroupquantile_avg))
64 tp = b->ttype;
65
66 if (grpfunc1) {
67 bn = (*grpfunc1)(b, g, e, s, tp, skip_nils, abort_on_error);
68 } else if (quantilefunc) {
69 assert(BATcount(q) > 0 || BATcount(b) == 0);
70 assert(q->ttype == TYPE_dbl);
71 if (BATcount(q) == 0) {
72 qvalue = 0.5;
73 } else {
74 qvalue = ((const dbl *)Tloc(q, 0))[0];
75 if (qvalue < 0 || qvalue > 1) {
76 BBPunfix(b->batCacheid);
77 if (g)
78 BBPunfix(g->batCacheid);
79 if (e)
80 BBPunfix(e->batCacheid);
81 if (s)
82 BBPunfix(s->batCacheid);
83 BBPunfix(q->batCacheid);
84 throw(MAL, malfunc,
85 "quantile value of %f is not in range [0,1]", qvalue);
86 }
87 }
88 BBPunfix(q->batCacheid);
89 bn = (*quantilefunc)(b, g, e, s, tp, qvalue, skip_nils, abort_on_error);
90 } else if ((*grpfunc2)(&bn, retval2 ? &cnts : NULL, b, g, e, s, tp,
91 skip_nils, abort_on_error, scale) != GDK_SUCCEED) {
92 bn = NULL;
93 }
94
95 BBPunfix(b->batCacheid);
96 if (g)
97 BBPunfix(g->batCacheid);
98 if (e)
99 BBPunfix(e->batCacheid);
100 if (s)
101 BBPunfix(s->batCacheid);
102 if (bn == NULL)
103 throw(MAL, malfunc, GDK_EXCEPTION);
104 *retval1 = bn->batCacheid;
105 BBPkeepref(bn->batCacheid);
106 if (retval2) {
107 *retval2 = cnts->batCacheid;
108 BBPkeepref(cnts->batCacheid);
109 }
110 return MAL_SUCCEED;
111}
112
113mal_export str AGGRsum3_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid);
114str
115AGGRsum3_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid)
116{
117 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_bte,
118 BATgroupsum, NULL, NULL, NULL, "aggr.sum");
119}
120
121mal_export str AGGRsum3_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid);
122str
123AGGRsum3_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid)
124{
125 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_sht,
126 BATgroupsum, NULL, NULL, NULL, "aggr.sum");
127}
128
129mal_export str AGGRsum3_int(bat *retval, const bat *bid, const bat *gid, const bat *eid);
130str
131AGGRsum3_int(bat *retval, const bat *bid, const bat *gid, const bat *eid)
132{
133 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_int,
134 BATgroupsum, NULL, NULL, NULL, "aggr.sum");
135}
136
137mal_export str AGGRsum3_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid);
138str
139AGGRsum3_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid)
140{
141 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_lng,
142 BATgroupsum, NULL, NULL, NULL, "aggr.sum");
143}
144
145#ifdef HAVE_HGE
146mal_export str AGGRsum3_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid);
147str
148AGGRsum3_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid)
149{
150 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_hge,
151 BATgroupsum, NULL, NULL, NULL, "aggr.sum");
152}
153#endif
154
155mal_export str AGGRsum3_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid);
156str
157AGGRsum3_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid)
158{
159 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_flt,
160 BATgroupsum, NULL, NULL, NULL, "aggr.sum");
161}
162
163mal_export str AGGRsum3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid);
164str
165AGGRsum3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
166{
167 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_dbl,
168 BATgroupsum, NULL, NULL, NULL, "aggr.sum");
169}
170
171mal_export str AGGRprod3_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid);
172str
173AGGRprod3_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid)
174{
175 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_bte,
176 BATgroupprod, NULL, NULL, NULL, "aggr.prod");
177}
178
179mal_export str AGGRprod3_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid);
180str
181AGGRprod3_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid)
182{
183 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_sht,
184 BATgroupprod, NULL, NULL, NULL, "aggr.prod");
185}
186
187mal_export str AGGRprod3_int(bat *retval, const bat *bid, const bat *gid, const bat *eid);
188str
189AGGRprod3_int(bat *retval, const bat *bid, const bat *gid, const bat *eid)
190{
191 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_int,
192 BATgroupprod, NULL, NULL, NULL, "aggr.prod");
193}
194
195mal_export str AGGRprod3_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid);
196str
197AGGRprod3_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid)
198{
199 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_lng,
200 BATgroupprod, NULL, NULL, NULL, "aggr.prod");
201}
202
203#ifdef HAVE_HGE
204mal_export str AGGRprod3_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid);
205str
206AGGRprod3_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid)
207{
208 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_hge,
209 BATgroupprod, NULL, NULL, NULL, "aggr.prod");
210}
211#endif
212
213mal_export str AGGRprod3_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid);
214str
215AGGRprod3_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid)
216{
217 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_flt,
218 BATgroupprod, NULL, NULL, NULL, "aggr.prod");
219}
220
221mal_export str AGGRprod3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid);
222str
223AGGRprod3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
224{
225 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_dbl,
226 BATgroupprod, NULL, NULL, NULL, "aggr.prod");
227}
228
229mal_export str AGGRavg13_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid);
230str
231AGGRavg13_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
232{
233 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_dbl,
234 NULL, BATgroupavg, NULL, NULL, "aggr.avg");
235}
236
237mal_export str AGGRavg23_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid);
238str
239AGGRavg23_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid)
240{
241 return AGGRgrouped(retval1, retval2, bid, gid, eid, NULL, 1, 1, 0, TYPE_dbl,
242 NULL, BATgroupavg, NULL, NULL, "aggr.avg");
243}
244
245mal_export str AGGRavg14_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, int *scale);
246str
247AGGRavg14_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, int *scale)
248{
249 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, *scale, TYPE_dbl,
250 NULL, BATgroupavg, NULL, NULL, "aggr.avg");
251}
252
253mal_export str AGGRavg24_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, int *scale);
254str
255AGGRavg24_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, int *scale)
256{
257 return AGGRgrouped(retval1, retval2, bid, gid, eid, NULL, 1, 1, *scale, TYPE_dbl,
258 NULL, BATgroupavg, NULL, NULL, "aggr.avg");
259}
260
261mal_export str AGGRstdev3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid);
262str
263AGGRstdev3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
264{
265 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_dbl,
266 BATgroupstdev_sample, NULL, NULL, NULL, "aggr.stdev");
267}
268
269mal_export str AGGRstdevp3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid);
270str
271AGGRstdevp3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
272{
273 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_dbl,
274 BATgroupstdev_population, NULL, NULL, NULL, "aggr.stdevp");
275}
276
277mal_export str AGGRvariance3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid);
278str
279AGGRvariance3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
280{
281 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_dbl,
282 BATgroupvariance_sample, NULL, NULL, NULL, "aggr.variance");
283}
284
285mal_export str AGGRvariancep3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid);
286str
287AGGRvariancep3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
288{
289 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_dbl,
290 BATgroupvariance_population, NULL, NULL, NULL, "aggr.variancep");
291}
292
293mal_export str AGGRcount3(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *ignorenils);
294str
295AGGRcount3(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *ignorenils)
296{
297 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *ignorenils, 1, 0, TYPE_lng,
298 BATgroupcount, NULL, NULL, NULL, "aggr.count");
299}
300
301mal_export str AGGRcount3nonils(bat *retval, const bat *bid, const bat *gid, const bat *eid);
302str
303AGGRcount3nonils(bat *retval, const bat *bid, const bat *gid, const bat *eid)
304{
305 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 1, 1, 0, TYPE_lng,
306 BATgroupcount, NULL, NULL, NULL, "aggr.count");
307}
308
309mal_export str AGGRcount3nils(bat *retval, const bat *bid, const bat *gid, const bat *eid);
310str
311AGGRcount3nils(bat *retval, const bat *bid, const bat *gid, const bat *eid)
312{
313 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, 0, 1, 0, TYPE_lng,
314 BATgroupcount, NULL, NULL, NULL, "aggr.count");
315}
316
317#include "algebra.h" /* for ALGprojection */
318mal_export str AGGRmin3(bat *retval, const bat *bid, const bat *gid, const bat *eid);
319str
320AGGRmin3(bat *retval, const bat *bid, const bat *gid, const bat *eid)
321{
322 bat tmpid;
323 str err;
324
325 err = AGGRgrouped(&tmpid, NULL, bid, gid, eid, NULL, 0, 1, 0, TYPE_oid,
326 BATgroupmin, NULL, NULL, NULL, "aggr.min");
327 if (err == MAL_SUCCEED) {
328 err = ALGprojection(retval, &tmpid, bid);
329 BBPrelease(tmpid);
330 }
331 return err;
332}
333
334mal_export str AGGRmax3(bat *retval, const bat *bid, const bat *gid, const bat *eid);
335str
336AGGRmax3(bat *retval, const bat *bid, const bat *gid, const bat *eid)
337{
338 bat tmpid;
339 str err;
340
341 err = AGGRgrouped(&tmpid, NULL, bid, gid, eid, NULL, 0, 1, 0, TYPE_oid,
342 BATgroupmax, NULL, NULL, NULL, "aggr.max");
343 if (err == MAL_SUCCEED) {
344 err = ALGprojection(retval, &tmpid, bid);
345 BBPrelease(tmpid);
346 }
347 return err;
348}
349
350mal_export str AGGRsubsum_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
351str
352AGGRsubsum_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
353{
354 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
355 *abort_on_error, 0, TYPE_bte, BATgroupsum, NULL,
356 NULL, NULL, "aggr.subsum");
357}
358
359mal_export str AGGRsubsum_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
360str
361AGGRsubsum_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
362{
363 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
364 *abort_on_error, 0, TYPE_sht, BATgroupsum, NULL,
365 NULL, NULL, "aggr.subsum");
366}
367
368mal_export str AGGRsubsum_int(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
369str
370AGGRsubsum_int(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
371{
372 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
373 *abort_on_error, 0, TYPE_int, BATgroupsum, NULL,
374 NULL, NULL, "aggr.subsum");
375}
376
377mal_export str AGGRsubsum_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
378str
379AGGRsubsum_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
380{
381 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
382 *abort_on_error, 0, TYPE_lng, BATgroupsum, NULL,
383 NULL, NULL, "aggr.subsum");
384}
385
386#ifdef HAVE_HGE
387mal_export str AGGRsubsum_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid, bit *skip_nils, bit *abort_on_error);
388str
389AGGRsubsum_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid, bit *skip_nils, bit *abort_on_error)
390{
391 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
392 *abort_on_error, 0, TYPE_hge, BATgroupsum, NULL,
393 NULL, NULL, "aggr.subsum");
394}
395#endif
396
397mal_export str AGGRsubsum_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
398str
399AGGRsubsum_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
400{
401 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
402 *abort_on_error, 0, TYPE_flt, BATgroupsum, NULL,
403 NULL, NULL, "aggr.subsum");
404}
405
406mal_export str AGGRsubsum_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
407str
408AGGRsubsum_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
409{
410 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
411 *abort_on_error, 0, TYPE_dbl, BATgroupsum, NULL,
412 NULL, NULL, "aggr.subsum");
413}
414
415mal_export str AGGRsubsumcand_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
416str
417AGGRsubsumcand_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
418{
419 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
420 *abort_on_error, 0, TYPE_bte, BATgroupsum, NULL,
421 NULL, NULL, "aggr.subsum");
422}
423
424mal_export str AGGRsubsumcand_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
425str
426AGGRsubsumcand_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
427{
428 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
429 *abort_on_error, 0, TYPE_sht, BATgroupsum, NULL,
430 NULL, NULL, "aggr.subsum");
431}
432
433mal_export str AGGRsubsumcand_int(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
434str
435AGGRsubsumcand_int(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
436{
437 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
438 *abort_on_error, 0, TYPE_int, BATgroupsum, NULL,
439 NULL, NULL, "aggr.subsum");
440}
441
442mal_export str AGGRsubsumcand_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
443str
444AGGRsubsumcand_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
445{
446 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
447 *abort_on_error, 0, TYPE_lng, BATgroupsum, NULL,
448 NULL, NULL, "aggr.subsum");
449}
450
451#ifdef HAVE_HGE
452mal_export str AGGRsubsumcand_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
453str
454AGGRsubsumcand_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
455{
456 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
457 *abort_on_error, 0, TYPE_hge, BATgroupsum, NULL,
458 NULL, NULL, "aggr.subsum");
459}
460#endif
461
462mal_export str AGGRsubsumcand_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
463str
464AGGRsubsumcand_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
465{
466 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
467 *abort_on_error, 0, TYPE_flt, BATgroupsum, NULL,
468 NULL, NULL, "aggr.subsum");
469}
470
471mal_export str AGGRsubsumcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
472str
473AGGRsubsumcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
474{
475 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
476 *abort_on_error, 0, TYPE_dbl, BATgroupsum, NULL,
477 NULL, NULL, "aggr.subsum");
478}
479
480mal_export str AGGRsubprod_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
481str
482AGGRsubprod_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
483{
484 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
485 *abort_on_error, 0, TYPE_bte, BATgroupprod, NULL,
486 NULL, NULL, "aggr.subprod");
487}
488
489mal_export str AGGRsubprod_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
490str
491AGGRsubprod_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
492{
493 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
494 *abort_on_error, 0, TYPE_sht, BATgroupprod, NULL,
495 NULL, NULL, "aggr.subprod");
496}
497
498mal_export str AGGRsubprod_int(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
499str
500AGGRsubprod_int(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
501{
502 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
503 *abort_on_error, 0, TYPE_int, BATgroupprod, NULL,
504 NULL, NULL, "aggr.subprod");
505}
506
507mal_export str AGGRsubprod_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
508str
509AGGRsubprod_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
510{
511 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
512 *abort_on_error, 0, TYPE_lng, BATgroupprod, NULL,
513 NULL, NULL, "aggr.subprod");
514}
515
516#ifdef HAVE_HGE
517mal_export str AGGRsubprod_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
518str
519AGGRsubprod_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
520{
521 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
522 *abort_on_error, 0, TYPE_hge, BATgroupprod, NULL,
523 NULL, NULL, "aggr.subprod");
524}
525#endif
526
527mal_export str AGGRsubprod_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
528str
529AGGRsubprod_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
530{
531 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
532 *abort_on_error, 0, TYPE_flt, BATgroupprod, NULL,
533 NULL, NULL, "aggr.subprod");
534}
535
536mal_export str AGGRsubprod_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
537str
538AGGRsubprod_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
539{
540 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
541 *abort_on_error, 0, TYPE_dbl, BATgroupprod, NULL,
542 NULL, NULL, "aggr.subprod");
543}
544
545mal_export str AGGRsubprodcand_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
546str
547AGGRsubprodcand_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
548{
549 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
550 *abort_on_error, 0, TYPE_bte, BATgroupprod, NULL,
551 NULL, NULL, "aggr.subprod");
552}
553
554mal_export str AGGRsubprodcand_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
555str
556AGGRsubprodcand_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
557{
558 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
559 *abort_on_error, 0, TYPE_sht, BATgroupprod, NULL,
560 NULL, NULL, "aggr.subprod");
561}
562
563mal_export str AGGRsubprodcand_int(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
564str
565AGGRsubprodcand_int(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
566{
567 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
568 *abort_on_error, 0, TYPE_int, BATgroupprod, NULL,
569 NULL, NULL, "aggr.subprod");
570}
571
572mal_export str AGGRsubprodcand_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
573str
574AGGRsubprodcand_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
575{
576 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
577 *abort_on_error, 0, TYPE_lng, BATgroupprod, NULL,
578 NULL, NULL, "aggr.subprod");
579}
580
581#ifdef HAVE_HGE
582mal_export str AGGRsubprodcand_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
583str
584AGGRsubprodcand_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
585{
586 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
587 *abort_on_error, 0, TYPE_hge, BATgroupprod, NULL,
588 NULL, NULL, "aggr.subprod");
589}
590#endif
591
592mal_export str AGGRsubprodcand_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
593str
594AGGRsubprodcand_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
595{
596 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
597 *abort_on_error, 0, TYPE_flt, BATgroupprod, NULL,
598 NULL, NULL, "aggr.subprod");
599}
600
601mal_export str AGGRsubprodcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
602str
603AGGRsubprodcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
604{
605 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
606 *abort_on_error, 0, TYPE_dbl, BATgroupprod, NULL,
607 NULL, NULL, "aggr.subprod");
608}
609
610mal_export str AGGRsubavg1_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
611str
612AGGRsubavg1_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
613{
614 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
615 *abort_on_error, 0, TYPE_dbl, NULL, BATgroupavg,
616 NULL, NULL, "aggr.subavg");
617}
618
619mal_export str AGGRsubavg1cand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
620str
621AGGRsubavg1cand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
622{
623 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
624 *abort_on_error, 0, TYPE_dbl, NULL, BATgroupavg,
625 NULL, NULL, "aggr.subavg");
626}
627
628mal_export str AGGRsubavg2_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
629str
630AGGRsubavg2_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
631{
632 return AGGRgrouped(retval1, retval2, bid, gid, eid, NULL, *skip_nils,
633 *abort_on_error, 0, TYPE_dbl, NULL, BATgroupavg,
634 NULL, NULL, "aggr.subavg");
635}
636
637mal_export str AGGRsubavg2cand_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
638str
639AGGRsubavg2cand_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
640{
641 return AGGRgrouped(retval1, retval2, bid, gid, eid, sid, *skip_nils,
642 *abort_on_error, 0, TYPE_dbl, NULL, BATgroupavg,
643 NULL, NULL, "aggr.subavg");
644}
645
646mal_export str AGGRsubavg1s_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error, int *scale);
647str
648AGGRsubavg1s_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error, int *scale)
649{
650 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
651 *abort_on_error, *scale, TYPE_dbl, NULL, BATgroupavg,
652 NULL, NULL, "aggr.subavg");
653}
654
655mal_export str AGGRsubavg1scand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error, int *scale);
656str
657AGGRsubavg1scand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error, int *scale)
658{
659 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
660 *abort_on_error, *scale, TYPE_dbl, NULL, BATgroupavg,
661 NULL, NULL, "aggr.subavg");
662}
663
664mal_export str AGGRsubavg2s_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error, int *scale);
665str
666AGGRsubavg2s_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error, int *scale)
667{
668 return AGGRgrouped(retval1, retval2, bid, gid, eid, NULL, *skip_nils,
669 *abort_on_error, *scale, TYPE_dbl, NULL, BATgroupavg,
670 NULL, NULL, "aggr.subavg");
671}
672
673mal_export str AGGRsubavg2scand_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error, int *scale);
674str
675AGGRsubavg2scand_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error, int *scale)
676{
677 return AGGRgrouped(retval1, retval2, bid, gid, eid, sid, *skip_nils,
678 *abort_on_error, *scale, TYPE_dbl, NULL, BATgroupavg,
679 NULL, NULL, "aggr.subavg");
680}
681
682mal_export str AGGRsubstdev_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
683str
684AGGRsubstdev_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
685{
686 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
687 *abort_on_error, 0, TYPE_dbl, BATgroupstdev_sample,
688 NULL, NULL, NULL, "aggr.substdev");
689}
690
691mal_export str AGGRsubstdevcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
692str
693AGGRsubstdevcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
694{
695 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
696 *abort_on_error, 0, TYPE_dbl, BATgroupstdev_sample,
697 NULL, NULL, NULL, "aggr.substdev");
698}
699
700mal_export str AGGRsubstdevp_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
701str
702AGGRsubstdevp_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
703{
704 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
705 *abort_on_error, 0, TYPE_dbl,
706 BATgroupstdev_population, NULL, NULL, NULL,
707 "aggr.substdevp");
708}
709
710mal_export str AGGRsubstdevpcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
711str
712AGGRsubstdevpcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
713{
714 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
715 *abort_on_error, 0, TYPE_dbl,
716 BATgroupstdev_population,
717 NULL, NULL, NULL, "aggr.substdevp");
718}
719
720mal_export str AGGRsubvariance_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
721str
722AGGRsubvariance_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
723{
724 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
725 *abort_on_error, 0, TYPE_dbl, BATgroupvariance_sample,
726 NULL, NULL, NULL, "aggr.subvariance");
727}
728
729mal_export str AGGRsubvariancecand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
730str
731AGGRsubvariancecand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
732{
733 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
734 *abort_on_error, 0, TYPE_dbl, BATgroupvariance_sample,
735 NULL, NULL, NULL, "aggr.subvariance");
736}
737
738mal_export str AGGRsubvariancep_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
739str
740AGGRsubvariancep_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
741{
742 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
743 *abort_on_error, 0, TYPE_dbl,
744 BATgroupvariance_population, NULL,
745 NULL, NULL, "aggr.subvariancep");
746}
747
748mal_export str AGGRsubvariancepcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
749str
750AGGRsubvariancepcand_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
751{
752 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
753 *abort_on_error, 0, TYPE_dbl,
754 BATgroupvariance_population, NULL,
755 NULL, NULL, "aggr.subvariancep");
756}
757
758mal_export str AGGRsubcount(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils);
759str
760AGGRsubcount(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils)
761{
762 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
763 0, 0, TYPE_lng, BATgroupcount, NULL, NULL,
764 NULL, "aggr.subcount");
765}
766
767mal_export str AGGRsubcountcand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils);
768str
769AGGRsubcountcand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils)
770{
771 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
772 0, 0, TYPE_lng, BATgroupcount, NULL,
773 NULL, NULL, "aggr.subcount");
774}
775
776mal_export str AGGRsubmin(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils);
777str
778AGGRsubmin(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils)
779{
780 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
781 0, 0, TYPE_oid, BATgroupmin, NULL,
782 NULL, NULL, "aggr.submin");
783}
784
785mal_export str AGGRsubmincand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils);
786str
787AGGRsubmincand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils)
788{
789 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
790 0, 0, TYPE_oid, BATgroupmin, NULL,
791 NULL, NULL, "aggr.submin");
792}
793
794mal_export str AGGRsubmax(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils);
795str
796AGGRsubmax(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils)
797{
798 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
799 0, 0, TYPE_oid, BATgroupmax, NULL,
800 NULL, NULL, "aggr.submax");
801}
802
803mal_export str AGGRsubmaxcand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils);
804str
805AGGRsubmaxcand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils)
806{
807 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
808 0, 0, TYPE_oid, BATgroupmax, NULL,
809 NULL, NULL, "aggr.submax");
810}
811
812mal_export str AGGRsubmincand_val(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils);
813str
814AGGRsubmincand_val(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils)
815{
816 bat tmpid;
817 str err;
818
819 err = AGGRgrouped(&tmpid, NULL, bid, gid, eid, sid, *skip_nils, 0,
820 0, TYPE_oid, BATgroupmin, NULL, NULL, NULL, "aggr.submin");
821 if (err == MAL_SUCCEED) {
822 err = ALGprojection(retval, &tmpid, bid);
823 BBPrelease(tmpid);
824 }
825 return err;
826}
827
828mal_export str AGGRsubmin_val(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils);
829str
830AGGRsubmin_val(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils)
831{
832 return AGGRsubmincand_val(retval, bid, gid, eid, NULL, skip_nils);
833}
834
835mal_export str AGGRsubmaxcand_val(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils);
836str
837AGGRsubmaxcand_val(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils)
838{
839 bat tmpid;
840 str err;
841
842 err = AGGRgrouped(&tmpid, NULL, bid, gid, eid, sid, *skip_nils, 0,
843 0, TYPE_oid, BATgroupmax, NULL, NULL, NULL, "aggr.submax");
844 if (err == MAL_SUCCEED) {
845 err = ALGprojection(retval, &tmpid, bid);
846 BBPrelease(tmpid);
847 }
848 return err;
849}
850
851mal_export str AGGRsubmax_val(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils);
852str
853AGGRsubmax_val(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils)
854{
855 return AGGRsubmaxcand_val(retval, bid, gid, eid, NULL, skip_nils);
856}
857
858mal_export str AGGRmedian(void *retval, const bat *bid);
859str
860AGGRmedian(void *retval, const bat *bid)
861{
862 str err;
863 bat rval;
864 if ((err = AGGRgrouped(&rval, NULL, bid, NULL, NULL, NULL, 1,
865 0, 0, TYPE_any, BATgroupmedian, NULL,
866 NULL, NULL, "aggr.submedian")) == MAL_SUCCEED) {
867 oid pos = 0;
868 err = ALGfetchoid(retval, &rval, &pos);
869 BBPrelease(rval);
870 }
871 return err;
872}
873
874mal_export str AGGRsubmedian(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils);
875str
876AGGRsubmedian(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils)
877{
878 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
879 0, 0, TYPE_any, BATgroupmedian, NULL,
880 NULL, NULL, "aggr.submedian");
881}
882
883mal_export str AGGRsubmediancand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils);
884str
885AGGRsubmediancand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils)
886{
887 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
888 0, 0, TYPE_any, BATgroupmedian, NULL,
889 NULL, NULL, "aggr.submedian");
890}
891
892/* quantile functions, could make median functions obsolete completely */
893mal_export str AGGRquantile(void *retval, const bat *bid, const bat *qid);
894str
895AGGRquantile(void *retval, const bat *bid, const bat *qid)
896{
897 str err;
898 bat rval;
899 if ((err = AGGRgrouped(&rval, NULL, bid, NULL, NULL, NULL, 1,
900 0, 0, TYPE_any, NULL, NULL, BATgroupquantile,
901 qid, "aggr.subquantile")) == MAL_SUCCEED) {
902 oid pos = 0;
903 err = ALGfetchoid(retval, &rval, &pos);
904 BBPrelease(rval);
905 }
906 return err;
907}
908
909mal_export str AGGRsubquantile(bat *retval, const bat *bid, const bat *quantile, const bat *gid, const bat *eid, const bit *skip_nils);
910str
911AGGRsubquantile(bat *retval, const bat *bid, const bat *quantile, const bat *gid, const bat *eid, const bit *skip_nils)
912{
913 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
914 0, 0, TYPE_any, NULL, NULL, BATgroupquantile,
915 quantile, "aggr.subquantile");
916}
917
918mal_export str AGGRsubquantilecand(bat *retval, const bat *bid, const bat *quantile, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils);
919str
920AGGRsubquantilecand(bat *retval, const bat *bid, const bat *quantile, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils)
921{
922 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
923 0, 0, TYPE_any, NULL, NULL, BATgroupquantile,
924 quantile, "aggr.subquantile");
925}
926
927mal_export str AGGRmedian_avg(dbl *retval, const bat *bid);
928str
929AGGRmedian_avg(dbl *retval, const bat *bid)
930{
931 str err;
932 bat rval;
933 if ((err = AGGRgrouped(&rval, NULL, bid, NULL, NULL, NULL, 1,
934 0, 0, TYPE_any, BATgroupmedian_avg, NULL,
935 NULL, NULL, "aggr.submedian_avg")) == MAL_SUCCEED) {
936 oid pos = 0;
937 err = ALGfetchoid(retval, &rval, &pos);
938 BBPrelease(rval);
939 }
940 return err;
941}
942
943mal_export str AGGRsubmedian_avg(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils);
944str
945AGGRsubmedian_avg(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils)
946{
947 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
948 0, 0, TYPE_any, BATgroupmedian_avg, NULL,
949 NULL, NULL, "aggr.submedian_avg");
950}
951
952mal_export str AGGRsubmediancand_avg(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils);
953str
954AGGRsubmediancand_avg(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils)
955{
956 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
957 0, 0, TYPE_any, BATgroupmedian_avg, NULL,
958 NULL, NULL, "aggr.submedian_avg");
959}
960
961/* quantile functions, could make median functions obsolete completely */
962mal_export str AGGRquantile_avg(dbl *retval, const bat *bid, const bat *qid);
963str
964AGGRquantile_avg(dbl *retval, const bat *bid, const bat *qid)
965{
966 str err;
967 bat rval;
968 if ((err = AGGRgrouped(&rval, NULL, bid, NULL, NULL, NULL, 1,
969 0, 0, TYPE_any, NULL, NULL, BATgroupquantile_avg,
970 qid, "aggr.subquantile_avg")) == MAL_SUCCEED) {
971 oid pos = 0;
972 err = ALGfetchoid(retval, &rval, &pos);
973 BBPrelease(rval);
974 }
975 return err;
976}
977
978mal_export str AGGRsubquantile_avg(bat *retval, const bat *bid, const bat *quantile, const bat *gid, const bat *eid, const bit *skip_nils);
979str
980AGGRsubquantile_avg(bat *retval, const bat *bid, const bat *quantile, const bat *gid, const bat *eid, const bit *skip_nils)
981{
982 return AGGRgrouped(retval, NULL, bid, gid, eid, NULL, *skip_nils,
983 0, 0, TYPE_any, NULL, NULL, BATgroupquantile_avg,
984 quantile, "aggr.subquantile_avg");
985}
986
987mal_export str AGGRsubquantilecand_avg(bat *retval, const bat *bid, const bat *quantile, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils);
988str
989AGGRsubquantilecand_avg(bat *retval, const bat *bid, const bat *quantile, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils)
990{
991 return AGGRgrouped(retval, NULL, bid, gid, eid, sid, *skip_nils,
992 0, 0, TYPE_any, NULL, NULL, BATgroupquantile_avg,
993 quantile, "aggr.subquantile_avg");
994}
995
996static str
997AGGRgroup_str_concat(bat *retval1, const bat *bid, const bat *gid, const bat *eid, const bat *sid, bool skip_nils,
998 bool abort_on_error, BAT *(*str_func)(BAT *, BAT *, BAT *, BAT *, bool, bool, const char *),
999 const char *separator, const char *malfunc)
1000{
1001 BAT *b, *g, *e, *s, *bn = NULL;
1002
1003 assert(str_func != NULL);
1004
1005 b = BATdescriptor(*bid);
1006 g = gid ? BATdescriptor(*gid) : NULL;
1007 e = eid ? BATdescriptor(*eid) : NULL;
1008 s = sid ? BATdescriptor(*sid) : NULL;
1009
1010 if (b == NULL || (gid != NULL && g == NULL) || (eid != NULL && e == NULL) ||
1011 (sid != NULL && s == NULL)) {
1012 if (b)
1013 BBPunfix(b->batCacheid);
1014 if (g)
1015 BBPunfix(g->batCacheid);
1016 if (e)
1017 BBPunfix(e->batCacheid);
1018 if (s)
1019 BBPunfix(s->batCacheid);
1020 throw(MAL, malfunc, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
1021 }
1022
1023 bn = (*str_func)(b, g, e, s, skip_nils, abort_on_error, separator);
1024
1025 BBPunfix(b->batCacheid);
1026 if (g)
1027 BBPunfix(g->batCacheid);
1028 if (e)
1029 BBPunfix(e->batCacheid);
1030 if (s)
1031 BBPunfix(s->batCacheid);
1032 if (bn == NULL)
1033 throw(MAL, malfunc, GDK_EXCEPTION);
1034 *retval1 = bn->batCacheid;
1035 BBPkeepref(bn->batCacheid);
1036 return MAL_SUCCEED;
1037}
1038
1039#define DEFAULT_SEPARATOR ","
1040
1041mal_export str AGGRstr_group_concat(bat *retval, const bat *bid, const bat *gid, const bat *eid);
1042str
1043AGGRstr_group_concat(bat *retval, const bat *bid, const bat *gid, const bat *eid)
1044{
1045 return AGGRgroup_str_concat(retval, bid, gid, eid, NULL, 1, 1, BATgroupstr_group_concat, DEFAULT_SEPARATOR,
1046 "aggr.str_group_concat");
1047}
1048
1049mal_export str AGGRsubstr_group_concat(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
1050str
1051AGGRsubstr_group_concat(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
1052{
1053 return AGGRgroup_str_concat(retval, bid, gid, eid, NULL, *skip_nils, *abort_on_error, BATgroupstr_group_concat,
1054 DEFAULT_SEPARATOR, "aggr.substr_group_concat");
1055}
1056
1057mal_export str AGGRsubstr_group_concatcand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
1058str
1059AGGRsubstr_group_concatcand(bat *retval, const bat *bid, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
1060{
1061 return AGGRgroup_str_concat(retval, bid, gid, eid, sid, *skip_nils, *abort_on_error, BATgroupstr_group_concat,
1062 DEFAULT_SEPARATOR, "aggr.substr_group_concat");
1063}
1064
1065#define GET_SEPARATOR(MAL_FUNC) \
1066 do { \
1067 BATiter bi; \
1068 sep = BATdescriptor(*sepp); \
1069 if (sep == NULL) \
1070 throw(MAL, MAL_FUNC, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); \
1071 bi = bat_iterator(sep); \
1072 separator = BUNtvar(bi, 0); \
1073 } while (0);
1074
1075mal_export str AGGRstr_group_concat_sep(bat *retval, const bat *bid, const bat *sepp, const bat *gid, const bat *eid);
1076str
1077AGGRstr_group_concat_sep(bat *retval, const bat *bid, const bat *sepp, const bat *gid, const bat *eid)
1078{
1079 BAT *sep = NULL;
1080 str separator = DEFAULT_SEPARATOR, msg = MAL_SUCCEED;
1081
1082 GET_SEPARATOR("aggr.str_group_concat_sep")
1083 msg = AGGRgroup_str_concat(retval, bid, gid, eid, NULL, 1, 1, BATgroupstr_group_concat, separator,
1084 "aggr.str_group_concat_sep");
1085 BBPunfix(sep->batCacheid);
1086 return msg;
1087}
1088
1089mal_export str AGGRsubstr_group_concat_sep(bat *retval, const bat *bid, const bat *sepp, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error);
1090str
1091AGGRsubstr_group_concat_sep(bat *retval, const bat *bid, const bat *sepp, const bat *gid, const bat *eid, const bit *skip_nils, const bit *abort_on_error)
1092{
1093 BAT *sep = NULL;
1094 str separator = DEFAULT_SEPARATOR, msg = MAL_SUCCEED;
1095
1096 GET_SEPARATOR("aggr.substr_group_concat_sep")
1097 msg = AGGRgroup_str_concat(retval, bid, gid, eid, NULL, *skip_nils, *abort_on_error, BATgroupstr_group_concat,
1098 separator, "aggr.substr_group_concat_sep");
1099 BBPunfix(sep->batCacheid);
1100 return msg;
1101}
1102
1103mal_export str AGGRsubstr_group_concatcand_sep(bat *retval, const bat *bid, const bat *sepp, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error);
1104str
1105AGGRsubstr_group_concatcand_sep(bat *retval, const bat *bid, const bat *sepp, const bat *gid, const bat *eid, const bat *sid, const bit *skip_nils, const bit *abort_on_error)
1106{
1107 BAT *sep = NULL;
1108 str separator = DEFAULT_SEPARATOR, msg = MAL_SUCCEED;
1109
1110 GET_SEPARATOR("aggr.substr_group_concat_sep")
1111 msg = AGGRgroup_str_concat(retval, bid, gid, eid, sid, *skip_nils, *abort_on_error, BATgroupstr_group_concat,
1112 separator, "aggr.substr_group_concat_sep");
1113 BBPunfix(sep->batCacheid);
1114 return msg;
1115}
1116