Changeset: b0d0fb4b2869 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b0d0fb4b2869
Modified Files:
        monetdb5/modules/atoms/uuid.c
        monetdb5/modules/kernel/bat5.c
        sql/backends/monet5/dict.c
        sql/backends/monet5/sql_cast.c
        sql/backends/monet5/sql_datetrunc.c
        sql/backends/monet5/sql_fround.c
        sql/backends/monet5/sql_fround_impl.h
        sql/backends/monet5/sql_round.c
        sql/backends/monet5/sql_round_impl.h
        sql/backends/monet5/sql_time.c
Branch: Jan2022
Log Message:

Propagate properties inside bat iterator


diffs (truncated from 833 to 300 lines):

diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -213,7 +213,7 @@ UUIDuuid2uuid_bulk(bat *res, const bat *
        struct canditer ci;
        BUN q = 0;
        oid off;
-       bool nils = false;
+       bool nils = false, btsorted = false, btrevsorted = false, btkey = false;
        BATiter bi;
 
        if (sid && !is_bat_nil(*sid)) {
@@ -256,22 +256,25 @@ UUIDuuid2uuid_bulk(bat *res, const bat *
                        nils |= is_uuid_nil(v);
                }
        }
+       btkey = b->tkey;
+       btsorted = b->tsorted;
+       btrevsorted = b->trevsorted;
        bat_iterator_end(&bi);
 
 bailout:
+       if (b)
+               BBPunfix(b->batCacheid);
+       if (s)
+               BBPunfix(s->batCacheid);
        if (dst) {                                      /* implies 
msg==MAL_SUCCEED */
                BATsetcount(dst, q);
                dst->tnil = nils;
                dst->tnonil = !nils;
-               dst->tkey = b->tkey;
-               dst->tsorted = b->tsorted;
-               dst->trevsorted = b->trevsorted;
+               dst->tkey = btkey;
+               dst->tsorted = btsorted;
+               dst->trevsorted = btrevsorted;
                BBPkeepref(*res = dst->batCacheid);
        }
-       if (b)
-               BBPunfix(b->batCacheid);
-       if (s)
-               BBPunfix(s->batCacheid);
        return msg;
 }
 
@@ -296,7 +299,7 @@ UUIDstr2uuid_bulk(bat *res, const bat *b
        struct canditer ci;
        BUN q = 0;
        oid off;
-       bool nils = false;
+       bool nils = false, btkey = false;
        size_t l = UUID_SIZE;
        ssize_t (*conv)(const char *, size_t *, void **, bool) = 
BATatoms[TYPE_uuid].atomFromStr;
 
@@ -344,23 +347,24 @@ UUIDstr2uuid_bulk(bat *res, const bat *b
                        nils |= strNil(v);
                }
        }
+       btkey = b->tkey;
        bat_iterator_end(&bi);
 
 bailout:
+       if (b)
+               BBPunfix(b->batCacheid);
+       if (s)
+               BBPunfix(s->batCacheid);
        if (dst && !msg) {
                BATsetcount(dst, q);
                dst->tnil = nils;
                dst->tnonil = !nils;
-               dst->tkey = b->tkey;
+               dst->tkey = btkey;
                dst->tsorted = BATcount(dst) <= 1;
                dst->trevsorted = BATcount(dst) <= 1;
                BBPkeepref(*res = dst->batCacheid);
        } else if (dst)
                BBPreclaim(dst);
-       if (b)
-               BBPunfix(b->batCacheid);
-       if (s)
-               BBPunfix(s->batCacheid);
        return msg;
 }
 
@@ -383,7 +387,7 @@ UUIDuuid2str_bulk(bat *res, const bat *b
        BUN q = 0;
        struct canditer ci;
        oid off;
-       bool nils = false;
+       bool nils = false, btkey = false;
        char buf[UUID_STRLEN + 2], *pbuf = buf;
        size_t l = sizeof(buf);
        ssize_t (*conv)(char **, size_t *, const void *, bool) = 
BATatoms[TYPE_uuid].atomToStr;
@@ -441,23 +445,24 @@ UUIDuuid2str_bulk(bat *res, const bat *b
                        nils |= strNil(buf);
                }
        }
+       btkey = b->tkey;
        bat_iterator_end(&bi);
 
 bailout:
+       if (b)
+               BBPunfix(b->batCacheid);
+       if (s)
+               BBPunfix(s->batCacheid);
        if (dst && !msg) {
                BATsetcount(dst, q);
                dst->tnil = nils;
                dst->tnonil = !nils;
-               dst->tkey = b->tkey;
+               dst->tkey = btkey;
                dst->tsorted = BATcount(dst) <= 1;
                dst->trevsorted = BATcount(dst) <= 1;
                BBPkeepref(*res = dst->batCacheid);
        } else if (dst)
                BBPreclaim(dst);
-       if (b)
-               BBPunfix(b->batCacheid);
-       if (s)
-               BBPunfix(s->batCacheid);
        return msg;
 }
 
diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c
--- a/monetdb5/modules/kernel/bat5.c
+++ b/monetdb5/modules/kernel/bat5.c
@@ -913,18 +913,18 @@ BKCshrinkBAT(bat *ret, const bat *bid, c
                }
                }
        }
+       bool btnonil = b->tnonil, btkey = b->tkey;
        bat_iterator_end(&bi);
+       BBPunfix(b->batCacheid);
+       BBPunfix(bs->batCacheid);
 
        BATsetcount(bn, cnt);
        bn->tsorted = false;
        bn->trevsorted = false;
        bn->tseqbase = oid_nil;
-       bn->tkey = b->tkey;
-       bn->tnonil = b->tnonil;
+       bn->tkey = btkey;
+       bn->tnonil = btnonil;
        bn->tnil = false;               /* can't be sure if values deleted */
-
-       BBPunfix(b->batCacheid);
-       BBPunfix(bs->batCacheid);
        BBPkeepref(*ret= bn->batCacheid);
        return MAL_SUCCEED;
 }
diff --git a/sql/backends/monet5/dict.c b/sql/backends/monet5/dict.c
--- a/sql/backends/monet5/dict.c
+++ b/sql/backends/monet5/dict.c
@@ -393,6 +393,7 @@ convert_oid( BAT *o, int rt)
        BATiter oi = bat_iterator(o);
        BAT *b = COLnew(o->hseqbase, rt, BATcount(o), TRANSIENT);
        int brokenrange = 0, nil = 0;
+       bool osorted = o->tsorted, okey = o->tkey;
 
        if (!b)
                return NULL;
@@ -435,8 +436,8 @@ convert_oid( BAT *o, int rt)
        BATsetcount(b, BATcount(o));
        BATnegateprops(b);
        if (!brokenrange)
-               b->tsorted = o->tsorted;
-       b->tkey = o->tkey;
+               b->tsorted = osorted;
+       b->tkey = okey;
        if (nil) {
                b->tnil = true;
                b->tnonil = false;
@@ -534,24 +535,32 @@ DICTrenumber_intern( BAT *o, BAT *lc, BA
        }
        if (o->ttype == TYPE_bte) {
                bte *op = Tloc(no, 0);
+               oid *c = Tloc(rc, 0);
+               BATiter oi = bat_iterator(o);
                unsigned char *ip = Tloc(o, 0);
-               oid *c = Tloc(rc, 0);
+               bool otkey = o->tkey;
+
                for(BUN i = 0; i<cnt; i++) {
                        op[i] = (bte) ((BUN)ip[i]==offcnt?offcnt:c[ip[i]]);
                }
+               bat_iterator_end(&oi);
                BATsetcount(no, cnt);
                BATnegateprops(no);
-               no->tkey = o->tkey;
+               no->tkey = otkey;
        } else if (o->ttype == TYPE_sht) {
                sht *op = Tloc(no, 0);
+               oid *c = Tloc(rc, 0);
+               BATiter oi = bat_iterator(o);
                unsigned short *ip = Tloc(o, 0);
-               oid *c = Tloc(rc, 0);
+               bool otkey = o->tkey;
+
                for(BUN i = 0; i<cnt; i++) {
                        op[i] = (sht) ((BUN)ip[i]==offcnt?offcnt:c[ip[i]]);
                }
+               bat_iterator_end(&oi);
                BATsetcount(no, cnt);
                BATnegateprops(no);
-               no->tkey = o->tkey;
+               no->tkey = otkey;
        } else {
                assert(0);
        }
diff --git a/sql/backends/monet5/sql_cast.c b/sql/backends/monet5/sql_cast.c
--- a/sql/backends/monet5/sql_cast.c
+++ b/sql/backends/monet5/sql_cast.c
@@ -49,7 +49,7 @@ batstr_2_blob(bat *res, const bat *bid, 
        oid off;
        blob *r = NULL;
        size_t rlen = 0;
-       bool nils = false;
+       bool nils = false, btkey = false;
 
        if ((b = BATdescriptor(*bid)) == NULL) {
                msg = createException(SQL, "batcalc.str_2_blob", 
SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
@@ -94,25 +94,26 @@ batstr_2_blob(bat *res, const bat *bid, 
                        nils |= strNil(v);
                }
        }
+       btkey = b->tkey;
 bailout1:
        bat_iterator_end(&bi);
 
 bailout:
        GDKfree(r);
+       if (b)
+               BBPunfix(b->batCacheid);
+       if (s)
+               BBPunfix(s->batCacheid);
        if (dst && !msg) {
                BATsetcount(dst, q);
                dst->tnil = nils;
                dst->tnonil = !nils;
-               dst->tkey = b->tkey;
+               dst->tkey = btkey;
                dst->tsorted = BATcount(dst) <= 1;
                dst->trevsorted = BATcount(dst) <= 1;
                BBPkeepref(*res = dst->batCacheid);
        } else if (dst)
                BBPreclaim(dst);
-       if (b)
-               BBPunfix(b->batCacheid);
-       if (s)
-               BBPunfix(s->batCacheid);
        return msg;
 }
 
@@ -219,7 +220,7 @@ SQLbatstr_cast(Client cntxt, MalBlkPtr m
        struct canditer ci;
        BUN q;
        oid off;
-       bool nils = false, from_str = EC_VARCHAR(eclass) || tpe == TYPE_str;
+       bool nils = false, from_str = EC_VARCHAR(eclass) || tpe == TYPE_str, 
btkey = false, btsorted = false, btrevsorted = false;
        size_t rlen = 0;
 
        if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
@@ -350,25 +351,28 @@ SQLbatstr_cast(Client cntxt, MalBlkPtr m
                        }
                }
        }
+       btkey = from_str ? b->tkey : q <= 1;
+       btsorted = from_str ? b->tsorted : q <= 1;
+       btrevsorted = from_str ? b->trevsorted : q <= 1;
 bailout1:
        bat_iterator_end(&bi);
 
 bailout:
        GDKfree(r);
+       if (b)
+               BBPunfix(b->batCacheid);
+       if (s)
+               BBPunfix(s->batCacheid);
        if (dst && !msg) {
                BATsetcount(dst, q);
                dst->tnil = nils;
                dst->tnonil = !nils;
-               dst->tkey = from_str ? b->tkey : BATcount(dst) <= 1;
-               dst->tsorted = from_str ? b->tsorted : BATcount(dst) <= 1;
-               dst->trevsorted = from_str ? b->trevsorted : BATcount(dst) <= 1;
+               dst->tkey = btkey;
+               dst->tsorted = btsorted;
+               dst->trevsorted = btrevsorted;
                BBPkeepref(*res = dst->batCacheid);
        } else if (dst)
                BBPreclaim(dst);
-       if (b)
-               BBPunfix(b->batCacheid);
-       if (s)
-               BBPunfix(s->batCacheid);
        return msg;
 }
 
diff --git a/sql/backends/monet5/sql_datetrunc.c 
b/sql/backends/monet5/sql_datetrunc.c
--- a/sql/backends/monet5/sql_datetrunc.c
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to