Changeset: 2216c1903de8 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2216c1903de8 Added Files: sql/backends/monet5/sql_subquery.c sql/backends/monet5/sql_subquery.h sql/backends/monet5/sql_subquery.mal Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/MAL-signatures.stable.out.int128 sql/backends/monet5/sql.c sql/backends/monet5/sql.mal sql/test/BugTracker-2019/Tests/All sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128 sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.powerpc64.int128 sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128 sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64 sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64.int128 sql/test/emptydb-upgrade-hge/Tests/upgrade.stable.out.int128 sql/test/emptydb-upgrade/Tests/upgrade.stable.out sql/test/emptydb-upgrade/Tests/upgrade.stable.out.32bit sql/test/emptydb-upgrade/Tests/upgrade.stable.out.int128 sql/test/mergetables/Tests/All sql/test/subquery/Tests/All sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out.int128 sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.32bit sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128 sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out.int128 sql/test/testdb-upgrade/Tests/upgrade.stable.out sql/test/testdb-upgrade/Tests/upgrade.stable.out.32bit sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128 Branch: sq2 Log Message:
merged with Nov2019 diffs (truncated from 2248 to 300 lines): diff --git a/clients/Tests/MAL-signatures.stable.out b/clients/Tests/MAL-signatures.stable.out --- a/clients/Tests/MAL-signatures.stable.out +++ b/clients/Tests/MAL-signatures.stable.out @@ -66,6 +66,7 @@ stdout of test 'MAL-signatures` in direc % clob, clob, clob, clob, clob # type % 11, 28, 364, 38, 874 # length [ "aggr", "allnotequal", "command aggr.allnotequal(l:bat[:any_1], r:bat[:any_1]):bit ", "SQLallnotequal;", "if all values in r are not equal to l return true, else if r has nil nil else false" ] +[ "aggr", "anyequal", "pattern aggr.anyequal(l:any_1, r:any_1):bit ", "CMDvarEQ;", "" ] [ "aggr", "anyequal", "command aggr.anyequal(l:bat[:any_1], r:bat[:any_1]):bit ", "SQLanyequal;", "if any value in r is equal to l return true, else if r has nil nil else false" ] [ "aggr", "avg", "command aggr.avg(b:bat[:bte], g:bat[:oid], e:bat[:any_1]):bat[:dbl] ", "AGGRavg13_dbl;", "Grouped tail average on bte" ] [ "aggr", "avg", "command aggr.avg(b:bat[:dbl], g:bat[:oid], e:bat[:any_1]):bat[:dbl] ", "AGGRavg13_dbl;", "Grouped tail average on dbl" ] @@ -128,6 +129,7 @@ stdout of test 'MAL-signatures` in direc [ "aggr", "min", "command aggr.min(b:bat[:any_1], g:bat[:oid], e:bat[:any_2]):bat[:any_1] ", "AGGRmin3;", "" ] [ "aggr", "min", "command aggr.min(b:bat[:any_2]):any_2 ", "ALGminany;", "Return the lowest tail value or nil." ] [ "aggr", "min", "command aggr.min(b:bat[:any_2], skipnil:bit):any_2 ", "ALGminany_skipnil;", "Return the lowest tail value or nil." ] +[ "aggr", "not_anyequal", "pattern aggr.not_anyequal(l:any_1, r:any_1):bit ", "CMDvarNE;", "" ] [ "aggr", "not_exist", "command aggr.not_exist(b:bat[:any_2]):bit ", "SQLnot_exist;", "" ] [ "aggr", "not_exist", "pattern aggr.not_exist(v:any_2):bit ", "SQLnot_exist_val;", "" ] [ "aggr", "prod", "command aggr.prod(b:bat[:bte], g:bat[:oid], e:bat[:any_1]):bat[:bte] ", "AGGRprod3_bte;", "Grouped tail product on bte" ] diff --git a/clients/Tests/MAL-signatures.stable.out.int128 b/clients/Tests/MAL-signatures.stable.out.int128 --- a/clients/Tests/MAL-signatures.stable.out.int128 +++ b/clients/Tests/MAL-signatures.stable.out.int128 @@ -70,6 +70,7 @@ stdout of test 'MAL-signatures` in direc % clob, clob, clob, clob, clob # type % 11, 28, 364, 38, 874 # length [ "aggr", "allnotequal", "command aggr.allnotequal(l:bat[:any_1], r:bat[:any_1]):bit ", "SQLallnotequal;", "if all values in r are not equal to l return true, else if r has nil nil else false" ] +[ "aggr", "anyequal", "pattern aggr.anyequal(l:any_1, r:any_1):bit ", "CMDvarEQ;", "" ] [ "aggr", "anyequal", "command aggr.anyequal(l:bat[:any_1], r:bat[:any_1]):bit ", "SQLanyequal;", "if any value in r is equal to l return true, else if r has nil nil else false" ] [ "aggr", "avg", "command aggr.avg(b:bat[:bte], g:bat[:oid], e:bat[:any_1]):bat[:dbl] ", "AGGRavg13_dbl;", "Grouped tail average on bte" ] [ "aggr", "avg", "command aggr.avg(b:bat[:dbl], g:bat[:oid], e:bat[:any_1]):bat[:dbl] ", "AGGRavg13_dbl;", "Grouped tail average on dbl" ] @@ -136,6 +137,7 @@ stdout of test 'MAL-signatures` in direc [ "aggr", "min", "command aggr.min(b:bat[:any_1], g:bat[:oid], e:bat[:any_2]):bat[:any_1] ", "AGGRmin3;", "" ] [ "aggr", "min", "command aggr.min(b:bat[:any_2]):any_2 ", "ALGminany;", "Return the lowest tail value or nil." ] [ "aggr", "min", "command aggr.min(b:bat[:any_2], skipnil:bit):any_2 ", "ALGminany_skipnil;", "Return the lowest tail value or nil." ] +[ "aggr", "not_anyequal", "pattern aggr.not_anyequal(l:any_1, r:any_1):bit ", "CMDvarNE;", "" ] [ "aggr", "not_exist", "command aggr.not_exist(b:bat[:any_2]):bit ", "SQLnot_exist;", "" ] [ "aggr", "not_exist", "pattern aggr.not_exist(v:any_2):bit ", "SQLnot_exist_val;", "" ] [ "aggr", "prod", "command aggr.prod(b:bat[:bte], g:bat[:oid], e:bat[:any_1]):bat[:bte] ", "AGGRprod3_bte;", "Grouped tail product on bte" ] diff --git a/sql/backends/monet5/sql_subquery.c b/sql/backends/monet5/sql_subquery.c new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/sql_subquery.c @@ -0,0 +1,948 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. + */ + +#include "monetdb_config.h" +#include "sql_subquery.h" + +str +zero_or_one_error(ptr ret, const bat *bid, const bit *err) +{ + BAT *b; + BUN c; + size_t _s; + const void *p; + + if ((b = BATdescriptor(*bid)) == NULL) { + throw(SQL, "zero_or_one", SQLSTATE(HY005) "Cannot access column descriptor"); + } + c = BATcount(b); + if (c == 0) { + p = ATOMnilptr(b->ttype); + } else if (c == 1 || (c > 1 && *err == false)) { + BATiter bi = bat_iterator(b); + p = BUNtail(bi, 0); + } else { + p = NULL; + BBPunfix(b->batCacheid); + throw(SQL, "zero_or_one", SQLSTATE(21000) "Cardinality violation, scalar value expected"); + } + _s = ATOMsize(ATOMtype(b->ttype)); + if (ATOMextern(b->ttype)) { + _s = ATOMlen(ATOMtype(b->ttype), p); + *(ptr *) ret = GDKmalloc(_s); + if(*(ptr *) ret == NULL){ + BBPunfix(b->batCacheid); + throw(SQL, "zero_or_one", SQLSTATE(HY001) MAL_MALLOC_FAIL); + } + memcpy(*(ptr *) ret, p, _s); + } else if (b->ttype == TYPE_bat) { + bat bid = *(bat *) p; + if((*(BAT **) ret = BATdescriptor(bid)) == NULL){ + BBPunfix(b->batCacheid); + throw(SQL, "zero_or_one", SQLSTATE(HY005) "Cannot access column descriptor"); + } + } else if (_s == 4) { + *(int *) ret = *(int *) p; + } else if (_s == 1) { + *(bte *) ret = *(bte *) p; + } else if (_s == 2) { + *(sht *) ret = *(sht *) p; + } else if (_s == 8) { + *(lng *) ret = *(lng *) p; +#ifdef HAVE_HGE + } else if (_s == 16) { + *(hge *) ret = *(hge *) p; +#endif + } else { + memcpy(ret, p, _s); + } + BBPunfix(b->batCacheid); + return MAL_SUCCEED; +} + +str +zero_or_one_error_bat(ptr ret, const bat *bid, const bat *err) +{ + bit t = FALSE; + (void)err; + return zero_or_one_error(ret, bid, &t); +} + +str +zero_or_one(ptr ret, const bat *bid) +{ + bit t = TRUE; + return zero_or_one_error(ret, bid, &t); +} + +str +SQLsubzero_or_one(bat *ret, const bat *bid, const bat *gid, const bat *eid, bit *no_nil) +{ + gdk_return r; + BAT *ng = NULL, *h = NULL, *g, *b; + + (void)no_nil; + (void)eid; + + g = gid ? BATdescriptor(*gid) : NULL; + if (g == NULL) { + if (g) + BBPunfix(g->batCacheid); + throw(MAL, "sql.subzero_or_one", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); + } + + if ((r = BATgroup(&ng, NULL, &h, g, NULL, NULL, NULL, NULL)) == GDK_SUCCEED) { + lng max = 0; + + if (ng) + BBPunfix(ng->batCacheid); + BATmax(h, &max); + BBPunfix(h->batCacheid); + if (max != lng_nil && max > 1) + throw(SQL, "assert", SQLSTATE(M0M29) "zero_or_one: cardinality violation, scalar expression expected"); + + } + BBPunfix(g->batCacheid); + if (r == GDK_SUCCEED) { + b = bid ? BATdescriptor(*bid) : NULL; + BBPkeepref(*ret = b->batCacheid); + } + return MAL_SUCCEED; +} + +str +SQLall(ptr ret, const bat *bid) +{ + BAT *b; + BUN c, _s; + const void *p; + + if ((b = BATdescriptor(*bid)) == NULL) { + throw(SQL, "all", SQLSTATE(HY005) "Cannot access column descriptor"); + } + c = BATcount(b); + if (c == 0) { + p = ATOMnilptr(b->ttype); + } else if (c == 1 || (b->tsorted && b->trevsorted)) { + BATiter bi = bat_iterator(b); + p = BUNtail(bi, 0); + } else if (b->ttype == TYPE_void && is_oid_nil(b->tseqbase)) { + p = ATOMnilptr(b->ttype); + } else { + BUN q, r; + int (*ocmp) (const void *, const void *); + const void *n = ATOMnilptr(b->ttype); + BATiter bi = bat_iterator(b); + r = BUNlast(b); + p = BUNtail(bi, 0); + ocmp = ATOMcompare(b->ttype); + for (q = 1; q < r; q++) { + const void *c = BUNtail(bi, q); + if (ocmp(p, c) != 0) { + if (ocmp(n, c) != 0) + p = ATOMnilptr(b->ttype); + break; + } + } + } + _s = ATOMsize(ATOMtype(b->ttype)); + if (ATOMextern(b->ttype)) { + _s = ATOMlen(ATOMtype(b->ttype), p); + *(ptr *) ret = GDKmalloc(_s); + if(*(ptr *) ret == NULL){ + BBPunfix(b->batCacheid); + throw(SQL, "SQLall", SQLSTATE(HY001) MAL_MALLOC_FAIL); + } + memcpy(*(ptr *) ret, p, _s); + } else if (b->ttype == TYPE_bat) { + bat bid = *(bat *) p; + if ((*(BAT **) ret = BATdescriptor(bid)) == NULL) { + BBPunfix(b->batCacheid); + throw(SQL, "all", SQLSTATE(HY005) "Cannot access column descriptor"); + } + } else if (_s == 4) { + *(int *) ret = *(int *) p; + } else if (_s == 1) { + *(bte *) ret = *(bte *) p; + } else if (_s == 2) { + *(sht *) ret = *(sht *) p; + } else if (_s == 8) { + *(lng *) ret = *(lng *) p; +#ifdef HAVE_HGE + } else if (_s == 16) { + *(hge *) ret = *(hge *) p; +#endif + } else { + memcpy(ret, p, _s); + } + BBPunfix(b->batCacheid); + return MAL_SUCCEED; +} + +str +SQLall_grp(bat *ret, const bat *bid, const bat *gp, const bat *gpe, bit *no_nil) +{ + BAT *l, *g, *e, *res; + BATiter li; + ssize_t p, *pos = NULL; + int error = 0, has_nil = 0; + int (*ocmp) (const void *, const void *); + + (void)no_nil; + if ((l = BATdescriptor(*bid)) == NULL) { + throw(SQL, "all =", SQLSTATE(HY005) "Cannot access column descriptor"); + } + if ((g = BATdescriptor(*gp)) == NULL) { + BBPunfix(l->batCacheid); + throw(SQL, "all =", SQLSTATE(HY005) "Cannot access column descriptor"); + } + if ((e = BATdescriptor(*gpe)) == NULL) { + BBPunfix(l->batCacheid); + BBPunfix(g->batCacheid); + throw(SQL, "all =", SQLSTATE(HY005) "Cannot access column descriptor"); + } + li = bat_iterator(l); + ocmp = ATOMcompare(l->ttype); + if (BATcount(g) > 0) { + BUN q, o, s, offset = 0; + BATiter gi = bat_iterator(g); + + pos = GDKmalloc(sizeof(BUN)*BATcount(e)); + for (s = 0; s < BATcount(e); s++) + pos[s] = -1; + + offset = g->hseqbase - l->hseqbase; + o = BUNlast(g); + for (q = offset, s = 0; s < o; q++, s++) { + oid id = *(oid*)BUNtail(gi, s); + if (pos[id] == -2) + continue; + else if (pos[id] == -1) + pos[id] = q; + else { + const void *lv = BUNtail(li, q); + const void *rv = BUNtail(li, pos[id]); + + if (ocmp(lv, rv) != 0) + pos[id] = -2; + } + } + } + res = COLnew(e->hseqbase, l->ttype, BATcount(e), TRANSIENT); + const void *nilp = ATOMnilptr(l->ttype); + for (p = 0; p < (ssize_t)BATcount(e) && !error; p++) { + const void *v = nilp; + if (pos[p] >= 0) { + v = BUNtail(li, pos[p]); + if (ocmp(v, nilp) == 0) + has_nil = 1; + } else + has_nil = 1; + if (BUNappend(res, v, false) != GDK_SUCCEED) + error = 1; + } + GDKfree(pos); + if (error) + throw(SQL, "all =", SQLSTATE(HY005) "all append failed"); + + res->hseqbase = g->hseqbase; + res->tnil = (has_nil)?1:0; + res->tnonil = (has_nil)?0:1; + res->tsorted = res->trevsorted = 0; + res->tkey = 0; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list