Changeset: c0fa09ba8e92 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c0fa09ba8e92
Modified Files:
        clients/Tests/MAL-signatures-hge.test
        monetdb5/modules/kernel/aggr.c
        monetdb5/modules/mal/calc.c
Branch: default
Log Message:

Reduce number of aggr.group_concat implementations to the ones we actually use.


diffs (truncated from 316 to 300 lines):

diff --git a/clients/Tests/MAL-signatures-hge.test 
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -1125,54 +1125,14 @@ ALGstdevp
 Gives the standard deviation of all tail values
 aggr
 str_group_concat
-command aggr.str_group_concat(X_0:bat[:str], X_1:bat[:oid], 
X_2:bat[:any_1]):bat[:str]
+command aggr.str_group_concat(X_0:bat[:str]):str
 AGGRstr_group_concat
-Grouped string tail concat
-aggr
-str_group_concat
-command aggr.str_group_concat(X_0:bat[:str], X_1:bat[:str], X_2:bat[:oid], 
X_3:bat[:any_1]):bat[:str]
-AGGRstr_group_concat_sep
-Grouped string tail concat with custom separator
-aggr
-str_group_concat
-pattern aggr.str_group_concat(X_0:bat[:str]):str
-CMDBATstr_group_concat
-Calculate aggregate string concatenate of B.
-aggr
-str_group_concat
-pattern aggr.str_group_concat(X_0:bat[:str], X_1:bat[:oid]):str
-CMDBATstr_group_concat
-Calculate aggregate string concatenate of B with candidate list.
+Ungrouped string tail concat
 aggr
 str_group_concat
-pattern aggr.str_group_concat(X_0:bat[:str], X_1:bat[:oid], X_2:bit):str
-CMDBATstr_group_concat
-Calculate aggregate string concatenate of B with candidate list.
-aggr
-str_group_concat
-pattern aggr.str_group_concat(X_0:bat[:str], X_1:bat[:str]):str
-CMDBATstr_group_concat
-Calculate aggregate string concatenate of B with separator SEP.
-aggr
-str_group_concat
-pattern aggr.str_group_concat(X_0:bat[:str], X_1:bat[:str], X_2:bat[:oid]):str
-CMDBATstr_group_concat
-Calculate aggregate string concatenate of B with candidate list and separator 
SEP.
-aggr
-str_group_concat
-pattern aggr.str_group_concat(X_0:bat[:str], X_1:bat[:str], X_2:bat[:oid], 
X_3:bit):str
-CMDBATstr_group_concat
-Calculate aggregate string concatenate of B with candidate list and separator 
SEP.
-aggr
-str_group_concat
-pattern aggr.str_group_concat(X_0:bat[:str], X_1:bat[:str], X_2:bit):str
-CMDBATstr_group_concat
-Calculate aggregate string concatenate of B with separator SEP.
-aggr
-str_group_concat
-pattern aggr.str_group_concat(X_0:bat[:str], X_1:bit):str
-CMDBATstr_group_concat
-Calculate aggregate string concatenate of B.
+command aggr.str_group_concat(X_0:bat[:str], X_1:bat[:str]):str
+AGGRstr_group_concat_sep
+Ungrouped string tail concat with custom separator
 aggr
 subCollect
 command aggr.subCollect(X_0:bat[:wkb], X_1:bat[:oid], X_2:bat[:oid], 
X_3:bit):bat[:wkb]
@@ -2224,16 +2184,6 @@ command aggr.substr_group_concat(X_0:bat
 AGGRsubstr_group_concat_sep
 Grouped string concat with custom separator
 aggr
-substr_group_concat
-command aggr.substr_group_concat(X_0:bat[:str], X_1:bat[:oid], 
X_2:bat[:any_1], X_3:bat[:oid], X_4:bit):bat[:str]
-AGGRsubstr_group_concatcand
-Grouped string concat with candidates list
-aggr
-substr_group_concat
-command aggr.substr_group_concat(X_0:bat[:str], X_1:bat[:str], X_2:bat[:oid], 
X_3:bat[:any_1], X_4:bat[:oid], X_5:bit):bat[:str]
-AGGRsubstr_group_concatcand_sep
-Grouped string concat with candidates list with custom separator
-aggr
 subsum
 command aggr.subsum(X_0:bat[:bte], X_1:bat[:oid], X_2:bat[:any_1], 
X_3:bit):bat[:bte]
 AGGRsubsum_bte
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
@@ -1100,50 +1100,60 @@ AGGRsubquantilecand_avg(bat *retval, con
 }
 
 static str
-AGGRgroup_str_concat(bat *retval1, const bat *bid, const bat *gid,
-                                        const bat *eid, const bat *sid, bool 
skip_nils,
+AGGRgroup_str_concat(bat *retval1, str *retval2, /* one or the other! */
+                                        const bat *bid, const bat *gid,
+                                        const bat *eid, bool skip_nils,
                                         const bat *sepid, const char 
*separator,
                                         const char *malfunc)
 {
-       BAT *b, *g, *e, *s, *sep, *bn = NULL;
+       BAT *b, *g, *e, *sep, *bn = NULL;
 
        b = BATdescriptor(*bid);
        g = gid ? BATdescriptor(*gid) : NULL;
        e = eid ? BATdescriptor(*eid) : NULL;
-       s = sid ? BATdescriptor(*sid) : NULL;
        sep = sepid ? BATdescriptor(*sepid) : NULL;
 
        if (b == NULL || (gid != NULL && g == NULL) || (eid != NULL && e == 
NULL) ||
-               (sid != NULL && s == NULL) || (sepid != NULL && sep == NULL)) {
+               (sepid != NULL && sep == NULL)) {
                BBPreclaim(b);
                BBPreclaim(g);
                BBPreclaim(e);
-               BBPreclaim(s);
                BBPreclaim(sep);
                throw(MAL, malfunc, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
        }
 
-       bn = BATgroupstr_group_concat(b, g, e, s, sep, skip_nils, separator);
+       if (retval1) {
+               bn = BATgroupstr_group_concat(b, g, e, NULL, sep, skip_nils, 
separator);
+       } else {
+               ValRecord res;
+               if (BATstr_group_concat(&res, b, NULL, sep, true, true, 
separator) == GDK_SUCCEED)
+                       *retval2 = res.val.sval;
+               else
+                       *retval2 = NULL;
+       }
 
        BBPunfix(b->batCacheid);
        BBPreclaim(g);
        BBPreclaim(e);
-       BBPreclaim(s);
        BBPreclaim(sep);
-       if (bn == NULL)
-               throw(MAL, malfunc, GDK_EXCEPTION);
-       *retval1 = bn->batCacheid;
-       BBPkeepref(bn);
+       if (retval1) {
+               if (bn == NULL)
+                       throw(MAL, malfunc, GDK_EXCEPTION);
+               *retval1 = bn->batCacheid;
+               BBPkeepref(bn);
+       } else {
+               if (*retval2 == NULL)
+                       throw(MAL, malfunc, GDK_EXCEPTION);
+       }
        return MAL_SUCCEED;
 }
 
 #define DEFAULT_SEPARATOR ","
 
 static str
-AGGRstr_group_concat(bat *retval, const bat *bid, const bat *gid,
-                                        const bat *eid)
+AGGRstr_group_concat(str *retval, const bat *bid)
 {
-       return AGGRgroup_str_concat(retval, bid, gid, eid, NULL, true, NULL,
+       return AGGRgroup_str_concat(NULL, retval, bid, NULL, NULL, true, NULL,
                                                                
DEFAULT_SEPARATOR, "aggr.str_group_concat");
 }
 
@@ -1151,25 +1161,16 @@ static str
 AGGRsubstr_group_concat(bat *retval, const bat *bid, const bat *gid,
                                                const bat *eid, const bit 
*skip_nils)
 {
-       return AGGRgroup_str_concat(retval, bid, gid, eid, NULL, *skip_nils, 
NULL,
-                                                               
DEFAULT_SEPARATOR, "aggr.substr_group_concat");
+       return AGGRgroup_str_concat(retval, NULL, bid, gid, eid, *skip_nils,
+                                                               NULL, 
DEFAULT_SEPARATOR,
+                                                               
"aggr.substr_group_concat");
 }
 
 static str
-AGGRsubstr_group_concatcand(bat *retval, const bat *bid, const bat *gid,
-                                                       const bat *eid, const 
bat *sid,
-                                                       const bit *skip_nils)
+AGGRstr_group_concat_sep(str *retval, const bat *bid, const bat *sep)
 {
-       return AGGRgroup_str_concat(retval, bid, gid, eid, sid, *skip_nils, 
NULL,
-                                                               
DEFAULT_SEPARATOR, "aggr.substr_group_concat");
-}
-
-static str
-AGGRstr_group_concat_sep(bat *retval, const bat *bid, const bat *sep,
-                                                const bat *gid, const bat *eid)
-{
-       return AGGRgroup_str_concat(retval, bid, gid, eid, NULL, true, sep, 
NULL,
-                                                               
"aggr.str_group_concat_sep");;
+       return AGGRgroup_str_concat(NULL, retval, bid, NULL, NULL, true, sep,
+                                                               NULL, 
"aggr.str_group_concat_sep");;
 }
 
 static str
@@ -1177,17 +1178,8 @@ AGGRsubstr_group_concat_sep(bat *retval,
                                                        const bat *gid, const 
bat *eid,
                                                        const bit *skip_nils)
 {
-       return AGGRgroup_str_concat(retval, bid, gid, eid, NULL, *skip_nils, 
sep,
-                                                               NULL, 
"aggr.substr_group_concat_sep");
-}
-
-static str
-AGGRsubstr_group_concatcand_sep(bat *retval, const bat *bid, const bat *sep,
-                                                               const bat *gid, 
const bat *eid, const bat *sid,
-                                                               const bit 
*skip_nils)
-{
-       return AGGRgroup_str_concat(retval, bid, gid, eid, sid, *skip_nils, sep,
-                                                               NULL, 
"aggr.substr_group_concat_sep");
+       return AGGRgroup_str_concat(retval, NULL, bid, gid, eid, *skip_nils,
+                                                               sep, NULL, 
"aggr.substr_group_concat_sep");
 }
 
 static str
@@ -1625,12 +1617,10 @@ mel_func aggr_init_funcs[] = {
  command("aggr", "quantile_avg", AGGRquantile_avg_cst, false, "Quantile 
aggregate", args(1,3, arg("",dbl),batargany("b",1),arg("q",dbl))),
  command("aggr", "subquantile_avg", AGGRsubquantile_avg, false, "Grouped 
quantile aggregate", args(1,6, 
batarg("",dbl),batargany("b",1),batarg("q",dbl),batarg("g",oid),batargany("e",2),arg("skip_nils",bit))),
  command("aggr", "subquantile_avg", AGGRsubquantilecand_avg, false, "Grouped 
quantile aggregate with candidate list", args(1,7, 
batarg("",dbl),batargany("b",1),batarg("q",dbl),batarg("g",oid),batargany("e",2),batarg("s",oid),arg("skip_nils",bit))),
- command("aggr", "str_group_concat", AGGRstr_group_concat, false, "Grouped 
string tail concat", args(1,4, 
batarg("",str),batarg("b",str),batarg("g",oid),batargany("e",1))),
+ command("aggr", "str_group_concat", AGGRstr_group_concat, false, "Ungrouped 
string tail concat", args(1,2, arg("",str),batarg("b",str))),
  command("aggr", "substr_group_concat", AGGRsubstr_group_concat, false, 
"Grouped string concat", args(1,5, 
batarg("",str),batarg("b",str),batarg("g",oid),batargany("e",1),arg("skip_nils",bit))),
- command("aggr", "substr_group_concat", AGGRsubstr_group_concatcand, false, 
"Grouped string concat with candidates list", args(1,6, 
batarg("",str),batarg("b",str),batarg("g",oid),batargany("e",1),batarg("s",oid),arg("skip_nils",bit))),
- command("aggr", "str_group_concat", AGGRstr_group_concat_sep, false, "Grouped 
string tail concat with custom separator", args(1,5, 
batarg("",str),batarg("b",str),batarg("sep",str),batarg("g",oid),batargany("e",1))),
+ command("aggr", "str_group_concat", AGGRstr_group_concat_sep, false, 
"Ungrouped string tail concat with custom separator", args(1,3, 
arg("",str),batarg("b",str),batarg("sep",str))),
  command("aggr", "substr_group_concat", AGGRsubstr_group_concat_sep, false, 
"Grouped string concat with custom separator", args(1,6, 
batarg("",str),batarg("b",str),batarg("sep",str),batarg("g",oid),batargany("e",1),arg("skip_nils",bit))),
- command("aggr", "substr_group_concat", AGGRsubstr_group_concatcand_sep, 
false, "Grouped string concat with candidates list with custom separator", 
args(1,7, 
batarg("",str),batarg("b",str),batarg("sep",str),batarg("g",oid),batargany("e",1),batarg("s",oid),arg("skip_nils",bit))),
 
  command("aggr", "subavg", AGGRavg3, false, "Grouped average aggregation", 
args(3,8, 
batarg("",bte),batarg("",lng),batarg("",lng),batarg("b",bte),batarg("g",oid),batargany("e",1),batarg("s",oid),arg("skip_nils",bit))),
  command("aggr", "subavg", AGGRavg3, false, "Grouped average aggregation", 
args(3,8, 
batarg("",sht),batarg("",lng),batarg("",lng),batarg("b",sht),batarg("g",oid),batargany("e",1),batarg("s",oid),arg("skip_nils",bit))),
diff --git a/monetdb5/modules/mal/calc.c b/monetdb5/modules/mal/calc.c
--- a/monetdb5/modules/mal/calc.c
+++ b/monetdb5/modules/mal/calc.c
@@ -861,71 +861,6 @@ CMDBATavg3comb(Client cntxt, MalBlkPtr m
        return MAL_SUCCEED;
 }
 
-static str
-CMDBATstr_group_concat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
-{
-       ValPtr ret = &stk->stk[getArg(pci, 0)];
-       bat bid = *getArgReference_bat(stk, pci, 1), sid = 0;
-       BAT *b, *s = NULL, *sep = NULL;
-       bool nil_if_empty = true;
-       int next_argument = 2;
-       const char *separator = ",";
-       gdk_return r;
-
-       (void) cntxt;
-
-       if ((b = BATdescriptor(bid)) == NULL)
-               throw(MAL, "aggr.str_group_concat",
-                         SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
-
-       if (isaBatType(getArgType(mb, pci, 2))) {
-               sid = *getArgReference_bat(stk, pci, 2);
-               if ((sep = BATdescriptor(sid)) == NULL) {
-                       BBPunfix(b->batCacheid);
-                       throw(MAL, "aggr.str_group_concat",
-                                 SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
-               }
-               if (sep->ttype == TYPE_str) {   /* the separator bat */
-                       next_argument = 3;
-                       separator = NULL;
-               }
-       }
-
-       if (pci->argc >= (next_argument + 1)) {
-               if (getArgType(mb, pci, next_argument) == TYPE_bit) {
-                       assert(pci->argc == (next_argument + 1));
-                       nil_if_empty = *getArgReference_bit(stk, pci, 
next_argument);
-               } else {
-                       if (next_argument == 3) {
-                               bat sid = *getArgReference_bat(stk, pci, 
next_argument);
-                               if (!is_bat_nil(sid) && (s = 
BATdescriptor(sid)) == NULL) {
-                                       BBPunfix(b->batCacheid);
-                                       BBPunfix(sep->batCacheid);
-                                       throw(MAL, "aggr.str_group_concat",
-                                                 SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
-                               }
-                       } else {
-                               s = sep;
-                               sep = NULL;
-                       }
-                       if (pci->argc >= (next_argument + 2)) {
-                               assert(pci->argc == (next_argument + 2));
-                               assert(getArgType(mb, pci, (next_argument + 1)) 
== TYPE_bit);
-                               nil_if_empty = *getArgReference_bit(stk, pci, 
(next_argument + 1));
-                       }
-               }
-       }
-
-       assert((separator && !sep) || (!separator && sep));
-       r = BATstr_group_concat(ret, b, s, sep, true, nil_if_empty, separator);
-       BBPunfix(b->batCacheid);
-       BBPreclaim(sep);
-       BBPreclaim(s);
-       if (r != GDK_SUCCEED)
-               return mythrow(MAL, "aggr.str_group_concat", OPERATION_FAILED);
-       return MAL_SUCCEED;
-}
-
 #include "mel.h"
 mel_func calc_init_funcs[] = {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to