Changeset: 755e7d8b4aac for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=755e7d8b4aac
Added Files:
        sql/backends/monet5/sql_subquery.c
        sql/backends/monet5/sql_subquery.h
        sql/backends/monet5/sql_subquery.mal
Modified Files:
        sql/backends/monet5/Makefile.ag
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.h
        sql/backends/monet5/sql.mal
        sql/backends/monet5/sql_rank.mal
Branch: Nov2019
Log Message:

moved subquery code into its own file


diffs (truncated from 2236 to 300 lines):

diff --git a/sql/backends/monet5/Makefile.ag b/sql/backends/monet5/Makefile.ag
--- a/sql/backends/monet5/Makefile.ag
+++ b/sql/backends/monet5/Makefile.ag
@@ -46,7 +46,7 @@ lib__sql = {
                sql_orderidx.c sql_orderidx.h \
                wlr.c wlr.h \
                sql_datetrunc.c \
-               sql_rank.c sql_rank.h
+               sql_rank.c sql_rank.h sql_subquery.c sql_subquery.h
        # libmapi on Windows for mcrypt_*
        LIBS = ../../server/libsqlserver \
                ../../storage/libstore \
@@ -64,7 +64,7 @@ headers_mal = {
        DIR = libdir/monetdb5
        SOURCES = sql_aggr_bte.mal  sql_aggr_flt.mal sql_aggr_dbl.mal  
sql_aggr_int.mal  sql_aggr_lng.mal \
                sql_aggr_sht.mal  sql_decimal.mal  sql_inspect.mal wlr.mal \
-               sql_rank.mal sqlcatalog.mal sql_transaction.mal  sql.mal
+               sql_subquery.mal sql_rank.mal sqlcatalog.mal 
sql_transaction.mal  sql.mal
 }
 
 headers_mal_hge = {
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3412,756 +3412,6 @@ mvc_bin_import_table_wrap(Client cntxt, 
 }
 
 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;
-       BBPunfix(l->batCacheid);
-       BBPunfix(g->batCacheid);
-       BBPunfix(e->batCacheid);
-       BBPkeepref(*ret = res->batCacheid);
-       return MAL_SUCCEED;
-}
-
-str
-SQLnil(bit *ret, const bat *bid)
-{
-       BAT *b;
-
-       if ((b = BATdescriptor(*bid)) == NULL) {
-               throw(SQL, "all", SQLSTATE(HY005) "Cannot access column 
descriptor");
-       }
-       *ret = FALSE;
-       if (BATcount(b) == 0)
-               *ret = bit_nil;
-       if (BATcount(b) > 0) {
-               BUN q, o;
-               int (*ocmp) (const void *, const void *);
-               BATiter bi = bat_iterator(b);
-               const void *nilp = ATOMnilptr(b->ttype);
-
-               o = BUNlast(b);
-               ocmp = ATOMcompare(b->ttype);
-               for (q = 0; q < o; q++) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to