Changeset: b956c3a51570 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b956c3a51570
Modified Files:
monetdb5/modules/kernel/aggr.c
Branch: Jul2017
Log Message:
Coalesce near-identical functions.
diffs (truncated from 1396 to 300 lines):
diff --git a/monetdb5/modules/kernel/aggr.c b/monetdb5/modules/kernel/aggr.c
--- a/monetdb5/modules/kernel/aggr.c
+++ b/monetdb5/modules/kernel/aggr.c
@@ -14,353 +14,19 @@
* grouped aggregates
*/
static str
-AGGRgrouped(bat *retval1, bat *retval2, BAT *b, BAT *g, BAT *e, int tp,
+AGGRgrouped(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const
bat *eid, const bat *sid,
+ int skip_nils, int abort_on_error, int tp,
BAT *(*grpfunc1)(BAT *, BAT *, BAT *, BAT *, int, int,
int),
gdk_return (*grpfunc2)(BAT **, BAT **, BAT *, BAT *,
BAT *, BAT *, int, int, int),
BAT *(*quantilefunc)(BAT *, BAT *, BAT *, BAT *, int,
double, int, int),
- BAT *quantile,
- int skip_nils,
+ const bat *quantile,
const char *malfunc)
{
- BAT *bn, *cnts = NULL;
- double qvalue;
-
- /* one of grpfunc1, grpfunc2 and quantilefunc is non-NULL and the others
are */
- assert((grpfunc1 != NULL && grpfunc2 == NULL && quantilefunc == NULL) ||
- (grpfunc1 == NULL && grpfunc2 != NULL && quantilefunc
== NULL) ||
- (grpfunc1 == NULL && grpfunc2 == NULL && quantilefunc
!= NULL) );
- /* if retval2 is non-NULL, we must have grpfunc2 */
- assert(retval2 == NULL || grpfunc2 != NULL);
-
- if (b == NULL || g == NULL || e == NULL ||
- (quantilefunc != NULL && quantile == NULL)) {
- if (b)
- BBPunfix(b->batCacheid);
- if (g)
- BBPunfix(g->batCacheid);
- if (e)
- BBPunfix(e->batCacheid);
- if (quantile)
- BBPunfix(quantile->batCacheid);
- throw(MAL, malfunc, RUNTIME_OBJECT_MISSING);
- }
- assert(quantile == NULL || quantilefunc != NULL);
- assert(b->hseqbase == g->hseqbase);
- assert(BATcount(b) == BATcount(g));
- if (tp == TYPE_any && (grpfunc1 == BATgroupmedian || quantilefunc ==
BATgroupquantile))
- tp = b->ttype;
- if (grpfunc1)
- bn = (*grpfunc1)(b, g, e, NULL, tp, skip_nils, 1);
- if (quantilefunc) {
- assert(BATcount(quantile)>0);
- assert(quantile->ttype == TYPE_dbl);
- qvalue = ((const double *)Tloc(quantile, 0))[0];
- if (qvalue < 0 || qvalue > 1) {
- BBPunfix(b->batCacheid);
- BBPunfix(g->batCacheid);
- BBPunfix(e->batCacheid);
- throw(MAL, malfunc, "quantile value of %f is not in
range [0,1]", qvalue);
- }
- bn = (*quantilefunc)(b, g, e, NULL, tp, qvalue, skip_nils, 1);
- BBPunfix(quantile->batCacheid);
- }
- if (grpfunc2 && (*grpfunc2)(&bn, retval2 ? &cnts : NULL, b, g, e, NULL,
tp, skip_nils, 1) != GDK_SUCCEED)
- bn = NULL;
- if (bn != NULL && (grpfunc1 == BATgroupmin || grpfunc1 == BATgroupmax))
{
- BAT *t = BATproject(bn, b);
- BBPunfix(bn->batCacheid);
- bn = t;
- }
- BBPunfix(b->batCacheid);
- BBPunfix(g->batCacheid);
- BBPunfix(e->batCacheid);
- if (bn == NULL) {
- char *errbuf = GDKerrbuf;
- char *s;
-
- if (errbuf && *errbuf) {
- if (strncmp(errbuf, "!ERROR: ", 8) == 0)
- errbuf += 8;
- if (strchr(errbuf, '!') == errbuf + 5) {
- s = createException(MAL, malfunc, "%s", errbuf);
- } else if ((s = strchr(errbuf, ':')) != NULL && s[1] ==
' ') {
- s = createException(MAL, malfunc, "%s", s + 2);
- } else {
- s = createException(MAL, malfunc, "%s", errbuf);
- }
- GDKclrerr();
- return s;
- }
- throw(MAL, malfunc, OPERATION_FAILED);
- }
- *retval1 = bn->batCacheid;
- BBPkeepref(bn->batCacheid);
- if (retval2) {
- *retval2 = cnts->batCacheid;
- BBPkeepref(cnts->batCacheid);
- }
- return MAL_SUCCEED;
-}
-
-static str
-AGGRgrouped3(bat *retval1, bat *retval2, const bat *bid, const bat *gid, const
bat *eid, int tp,
- BAT *(*grpfunc1)(BAT *, BAT *, BAT *, BAT *, int, int,
int),
- gdk_return (*grpfunc2)(BAT **, BAT **, BAT *, BAT *,
BAT *, BAT *, int, int, int),
- int skip_nils,
- const char *malfunc)
-{
- BAT *b, *g, *e;
-
- b = BATdescriptor(*bid); /* [head,value] */
- g = BATdescriptor(*gid); /* [head,gid] */
- e = BATdescriptor(*eid); /* [gid,any] */
- return AGGRgrouped(retval1, retval2, b, g, e, tp, grpfunc1, grpfunc2,
NULL, 0, skip_nils, malfunc);
-}
-
-mal_export str AGGRsum3_bte(bat *retval, const bat *bid, const bat *gid, const
bat *eid);
-str
-AGGRsum3_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_bte,
- BATgroupsum, NULL, 1,
"aggr.sum");
-}
-
-mal_export str AGGRsum3_sht(bat *retval, const bat *bid, const bat *gid, const
bat *eid);
-str
-AGGRsum3_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_sht,
- BATgroupsum, NULL, 1,
"aggr.sum");
-}
-
-mal_export str AGGRsum3_int(bat *retval, const bat *bid, const bat *gid, const
bat *eid);
-str
-AGGRsum3_int(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_int,
- BATgroupsum, NULL, 1,
"aggr.sum");
-}
-
-mal_export str AGGRsum3_lng(bat *retval, const bat *bid, const bat *gid, const
bat *eid);
-str
-AGGRsum3_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_lng,
- BATgroupsum, NULL, 1,
"aggr.sum");
-}
-
-#ifdef HAVE_HGE
-mal_export str AGGRsum3_hge(bat *retval, const bat *bid, const bat *gid, const
bat *eid);
-str
-AGGRsum3_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_hge,
- BATgroupsum, NULL, 1,
"aggr.sum");
-}
-#endif
-
-mal_export str AGGRsum3_flt(bat *retval, const bat *bid, const bat *gid, const
bat *eid);
-str
-AGGRsum3_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_flt,
- BATgroupsum, NULL, 1,
"aggr.sum");
-}
-
-mal_export str AGGRsum3_dbl(bat *retval, const bat *bid, const bat *gid, const
bat *eid);
-str
-AGGRsum3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_dbl,
- BATgroupsum, NULL, 1,
"aggr.sum");
-}
-
-mal_export str AGGRprod3_bte(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRprod3_bte(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_bte,
- BATgroupprod, NULL, 1,
"aggr.prod");
-}
-
-mal_export str AGGRprod3_sht(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRprod3_sht(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_sht,
- BATgroupprod, NULL, 1,
"aggr.prod");
-}
-
-mal_export str AGGRprod3_int(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRprod3_int(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_int,
- BATgroupprod, NULL, 1,
"aggr.prod");
-}
-
-mal_export str AGGRprod3_lng(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRprod3_lng(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_lng,
- BATgroupprod, NULL, 1,
"aggr.prod");
-}
-
-#ifdef HAVE_HGE
-mal_export str AGGRprod3_hge(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRprod3_hge(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_hge,
- BATgroupprod, NULL, 1,
"aggr.prod");
-}
-#endif
-
-mal_export str AGGRprod3_flt(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRprod3_flt(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_flt,
- BATgroupprod, NULL, 1,
"aggr.prod");
-}
-
-mal_export str AGGRprod3_dbl(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRprod3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_dbl,
- BATgroupprod, NULL, 1,
"aggr.prod");
-}
-
-mal_export str AGGRavg13_dbl(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRavg13_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_dbl,
- NULL, BATgroupavg, 1,
"aggr.avg");
-}
-
-mal_export str AGGRavg23_dbl(bat *retval1, bat *retval2, const bat *bid, const
bat *gid, const bat *eid);
-str
-AGGRavg23_dbl(bat *retval1, bat *retval2, const bat *bid, const bat *gid,
const bat *eid)
-{
- return AGGRgrouped3(retval1, retval2, bid, gid, eid, TYPE_dbl,
- NULL, BATgroupavg, 1,
"aggr.avg");
-}
-
-mal_export str AGGRstdev3_dbl(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRstdev3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_dbl,
- BATgroupstdev_sample, NULL, 1,
"aggr.stdev");
-}
-
-mal_export str AGGRstdevp3_dbl(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRstdevp3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_dbl,
- BATgroupstdev_population, NULL,
1, "aggr.stdevp");
-}
-
-mal_export str AGGRvariance3_dbl(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRvariance3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_dbl,
- BATgroupvariance_sample, NULL,
1, "aggr.variance");
-}
-
-mal_export str AGGRvariancep3_dbl(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRvariancep3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_dbl,
- BATgroupvariance_population,
NULL, 1, "aggr.variancep");
-}
-
-mal_export str AGGRcount3(bat *retval, const bat *bid, const bat *gid, const
bat *eid, const bit *ignorenils);
-str
-AGGRcount3(bat *retval, const bat *bid, const bat *gid, const bat *eid, const
bit *ignorenils)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_lng,
- BATgroupcount, NULL,
*ignorenils, "aggr.count");
-}
-
-mal_export str AGGRcount3nonils(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRcount3nonils(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_lng,
- BATgroupcount, NULL, 1,
"aggr.count");
-}
-
-mal_export str AGGRcount3nils(bat *retval, const bat *bid, const bat *gid,
const bat *eid);
-str
-AGGRcount3nils(bat *retval, const bat *bid, const bat *gid, const bat *eid)
-{
- return AGGRgrouped3(retval, NULL, bid, gid, eid, TYPE_lng,
- BATgroupcount, NULL, 0,
"aggr.count");
-}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list