Changeset: 3df030ca51dd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3df030ca51dd
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.h
        sql/backends/monet5/sql_round_impl.h
Branch: default
Log Message:

Added bulk implementation of decimal to second interval conversions, small 
cleanup and look for null values


diffs (261 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
@@ -6428,6 +6428,10 @@ stdout of test 'MAL-signatures` in direc
 [ "batcalc",   "or",   "pattern batcalc.or(X_1:sht, X_2:bat[:sht], 
X_3:bat[:oid]):bat[:sht] ", "CMDbatOR;",    ""      ]
 [ "batcalc",   "or",   "pattern batcalc.or(X_1:sht, X_2:bat[:sht], 
X_3:bat[:oid], X_4:bat[:bit]):bat[:sht] ",  "CMDbatOR;",    ""      ]
 [ "batcalc",   "rotate_xor_hash",      "command 
batcalc.rotate_xor_hash(X_1:bat[:lng], X_2:int, X_3:bat[:any_1]):bat[:int] ",  
"MKEYbulk_rotate_xor_hash;",    ""      ]
+[ "batcalc",   "second_interval",      "command 
batcalc.second_interval(X_1:int, X_2:bat[:bte], X_3:int, X_4:int):bat[:lng] ", 
"bte_batdec2second_interval;",  ""      ]
+[ "batcalc",   "second_interval",      "command 
batcalc.second_interval(X_1:int, X_2:bat[:hge], X_3:int, X_4:int):bat[:lng] ", 
"hge_batdec2second_interval;",  ""      ]
+[ "batcalc",   "second_interval",      "command 
batcalc.second_interval(X_1:int, X_2:bat[:int], X_3:int, X_4:int):bat[:lng] ", 
"int_batdec2second_interval;",  ""      ]
+[ "batcalc",   "second_interval",      "command 
batcalc.second_interval(X_1:int, X_2:bat[:lng], X_3:int, X_4:int):bat[:lng] ", 
"lng_batdec2second_interval;",  ""      ]
 [ "batcalc",   "second_interval",      "pattern 
batcalc.second_interval(X_1:bat[:bte], X_2:int, X_3:int):bat[:lng] ",  
"second_interval;",     ""      ]
 [ "batcalc",   "second_interval",      "pattern 
batcalc.second_interval(X_1:bat[:int], X_2:int, X_3:int):bat[:lng] ",  
"second_interval;",     ""      ]
 [ "batcalc",   "second_interval",      "pattern 
batcalc.second_interval(X_1:bat[:lng], X_2:int, X_3:int):bat[:lng] ",  
"second_interval;",     ""      ]
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
@@ -8979,11 +8979,16 @@ stdout of test 'MAL-signatures` in direc
 [ "batcalc",   "or",   "pattern batcalc.or(X_1:sht, X_2:bat[:sht], 
X_3:bat[:oid]):bat[:sht] ", "CMDbatOR;",    ""      ]
 [ "batcalc",   "or",   "pattern batcalc.or(X_1:sht, X_2:bat[:sht], 
X_3:bat[:oid], X_4:bat[:bit]):bat[:sht] ",  "CMDbatOR;",    ""      ]
 [ "batcalc",   "rotate_xor_hash",      "command 
batcalc.rotate_xor_hash(X_1:bat[:lng], X_2:int, X_3:bat[:any_1]):bat[:int] ",  
"MKEYbulk_rotate_xor_hash;",    ""      ]
+[ "batcalc",   "second_interval",      "command 
batcalc.second_interval(X_1:int, X_2:bat[:bte], X_3:int, X_4:int):bat[:lng] ", 
"bte_batdec2second_interval;",  ""      ]
+[ "batcalc",   "second_interval",      "command 
batcalc.second_interval(X_1:int, X_2:bat[:hge], X_3:int, X_4:int):bat[:lng] ", 
"hge_batdec2second_interval;",  ""      ]
+[ "batcalc",   "second_interval",      "command 
batcalc.second_interval(X_1:int, X_2:bat[:int], X_3:int, X_4:int):bat[:lng] ", 
"int_batdec2second_interval;",  ""      ]
+[ "batcalc",   "second_interval",      "command 
batcalc.second_interval(X_1:int, X_2:bat[:lng], X_3:int, X_4:int):bat[:lng] ", 
"lng_batdec2second_interval;",  ""      ]
 [ "batcalc",   "second_interval",      "pattern 
batcalc.second_interval(X_1:bat[:bte], X_2:int, X_3:int):bat[:lng] ",  
"second_interval;",     ""      ]
 [ "batcalc",   "second_interval",      "pattern 
batcalc.second_interval(X_1:bat[:hge], X_2:int, X_3:int):bat[:lng] ",  
"second_interval;",     ""      ]
 [ "batcalc",   "second_interval",      "pattern 
batcalc.second_interval(X_1:bat[:int], X_2:int, X_3:int):bat[:lng] ",  
"second_interval;",     ""      ]
 [ "batcalc",   "second_interval",      "pattern 
batcalc.second_interval(X_1:bat[:lng], X_2:int, X_3:int):bat[:lng] ",  
"second_interval;",     ""      ]
 [ "batcalc",   "second_interval",      "pattern 
batcalc.second_interval(X_1:bat[:sht], X_2:int, X_3:int):bat[:lng] ",  
"second_interval;",     ""      ]
+[ "batcalc",   "second_interval",      "command 
batcalc.second_interval(X_1:int, X_2:bat[:sht], X_3:int, X_4:int):bat[:lng] ", 
"sht_batdec2second_interval;",  ""      ]
 [ "batcalc",   "sht",  "pattern batcalc.sht(X_1:bat[:bit]):bat[:sht] ",        
"CMDconvertsignal_sht;",        ""      ]
 [ "batcalc",   "sht",  "pattern batcalc.sht(X_1:bat[:bit], 
X_2:bat[:bit]):bat[:sht] ", "CMDconvertsignal_sht;",        ""      ]
 [ "batcalc",   "sht",  "pattern batcalc.sht(X_1:bat[:bit], 
X_2:bat[:oid]):bat[:sht] ", "CMDconvertsignal_sht;",        ""      ]
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
@@ -3994,7 +3994,6 @@ bailout:
        do { \
                if (is_##TPE##_nil(IN)) { \
                        OUT = lng_nil; \
-                       hasnil = 1; \
                } else { \
                        lng r = (lng) IN; \
                        r *= multiplier; \
@@ -4016,7 +4015,6 @@ second_interval(Client cntxt, MalBlkPtr 
        BAT *b = NULL, *res = NULL;
        bat *r;
        BUN q = 0;
-       bit hasnil = 0;
 
        (void) cntxt;
        if (pci->argc > 3)
@@ -4090,18 +4088,18 @@ second_interval(Client cntxt, MalBlkPtr 
        }
 
 bailout:
-       if (b)
-               BBPunfix(b->batCacheid);
        if (res && !msg) {
                BATsetcount(res, q);
-               res->tnil = hasnil != 0;
-               res->tnonil = hasnil == 0;
+               res->tnil = b->tnil;
+               res->tnonil = b->tnonil;
                res->tkey = BATcount(res) <= 1;
                res->tsorted = BATcount(res) <= 1;
                res->trevsorted = BATcount(res) <= 1;
                BBPkeepref(*r = res->batCacheid);
        } else if (res)
                BBPreclaim(res);
+       if (b)
+               BBPunfix(b->batCacheid);
        return msg;
 }
 
@@ -6095,21 +6093,25 @@ static mel_func sql_init_funcs[] = {
  command("sql", "round", bte_round_wrap, false, "round off the decimal v(d,s) 
to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
arg("",bte),arg("v",bte),arg("d",int),arg("s",int),arg("r",bte))),
  command("batsql", "round", bte_bat_round_wrap, false, "round off the decimal 
v(d,s) to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
batarg("",bte),batarg("v",bte),arg("d",int),arg("s",int),arg("r",bte))),
  command("calc", "second_interval", bte_dec2second_interval, false, "cast bte 
decimal to a second_interval", args(1,5, 
arg("",lng),arg("sc",int),arg("v",bte),arg("ek",int),arg("sk",int))),
+ command("batcalc", "second_interval", bte_batdec2second_interval, false, 
"cast bte decimal to a second_interval", args(1,5, 
batarg("",lng),arg("sc",int),batarg("v",bte),arg("ek",int),arg("sk",int))),
  command("sql", "dec_round", sht_dec_round_wrap, false, "round off the value v 
to nearests multiple of r", args(1,3, arg("",sht),arg("v",sht),arg("r",sht))),
  command("batsql", "dec_round", sht_bat_dec_round_wrap, false, "round off the 
value v to nearests multiple of r", args(1,3, 
batarg("",sht),batarg("v",sht),arg("r",sht))),
  command("sql", "round", sht_round_wrap, false, "round off the decimal v(d,s) 
to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
arg("",sht),arg("v",sht),arg("d",int),arg("s",int),arg("r",bte))),
  command("batsql", "round", sht_bat_round_wrap, false, "round off the decimal 
v(d,s) to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
batarg("",sht),batarg("v",sht),arg("d",int),arg("s",int),arg("r",bte))),
  command("calc", "second_interval", sht_dec2second_interval, false, "cast sht 
decimal to a second_interval", args(1,5, 
arg("",lng),arg("sc",int),arg("v",sht),arg("ek",int),arg("sk",int))),
+ command("batcalc", "second_interval", sht_batdec2second_interval, false, 
"cast sht decimal to a second_interval", args(1,5, 
batarg("",lng),arg("sc",int),batarg("v",sht),arg("ek",int),arg("sk",int))), 
  command("sql", "dec_round", int_dec_round_wrap, false, "round off the value v 
to nearests multiple of r", args(1,3, arg("",int),arg("v",int),arg("r",int))),
  command("batsql", "dec_round", int_bat_dec_round_wrap, false, "round off the 
value v to nearests multiple of r", args(1,3, 
batarg("",int),batarg("v",int),arg("r",int))),
  command("sql", "round", int_round_wrap, false, "round off the decimal v(d,s) 
to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
arg("",int),arg("v",int),arg("d",int),arg("s",int),arg("r",bte))),
  command("batsql", "round", int_bat_round_wrap, false, "round off the decimal 
v(d,s) to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
batarg("",int),batarg("v",int),arg("d",int),arg("s",int),arg("r",bte))),
  command("calc", "second_interval", int_dec2second_interval, false, "cast int 
decimal to a second_interval", args(1,5, 
arg("",lng),arg("sc",int),arg("v",int),arg("ek",int),arg("sk",int))),
+ command("batcalc", "second_interval", int_batdec2second_interval, false, 
"cast int decimal to a second_interval", args(1,5, 
batarg("",lng),arg("sc",int),batarg("v",int),arg("ek",int),arg("sk",int))), 
  command("sql", "dec_round", lng_dec_round_wrap, false, "round off the value v 
to nearests multiple of r", args(1,3, arg("",lng),arg("v",lng),arg("r",lng))),
  command("batsql", "dec_round", lng_bat_dec_round_wrap, false, "round off the 
value v to nearests multiple of r", args(1,3, 
batarg("",lng),batarg("v",lng),arg("r",lng))),
  command("sql", "round", lng_round_wrap, false, "round off the decimal v(d,s) 
to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
arg("",lng),arg("v",lng),arg("d",int),arg("s",int),arg("r",bte))),
  command("batsql", "round", lng_bat_round_wrap, false, "round off the decimal 
v(d,s) to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
batarg("",lng),batarg("v",lng),arg("d",int),arg("s",int),arg("r",bte))),
  command("calc", "second_interval", lng_dec2second_interval, false, "cast lng 
decimal to a second_interval", args(1,5, 
arg("",lng),arg("sc",int),arg("v",lng),arg("ek",int),arg("sk",int))),
+ command("batcalc", "second_interval", lng_batdec2second_interval, false, 
"cast lng decimal to a second_interval", args(1,5, 
batarg("",lng),arg("sc",int),batarg("v",lng),arg("ek",int),arg("sk",int))), 
  command("sql", "dec_round", flt_dec_round_wrap, false, "round off the value v 
to nearests multiple of r", args(1,3, arg("",flt),arg("v",flt),arg("r",flt))),
  command("batsql", "dec_round", flt_bat_dec_round_wrap, false, "round off the 
value v to nearests multiple of r", args(1,3, 
batarg("",flt),batarg("v",flt),arg("r",flt))),
  command("sql", "round", flt_round_wrap, false, "round off the floating point 
v to r digits behind the dot (if r < 0, before the dot)", args(1,3, 
arg("",flt),arg("v",flt),arg("r",bte))),
@@ -6925,6 +6927,7 @@ static mel_func sql_init_funcs[] = {
  command("sql", "round", hge_round_wrap, false, "round off the decimal v(d,s) 
to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
arg("",hge),arg("v",hge),arg("d",int),arg("s",int),arg("r",bte))),
  command("batsql", "round", hge_bat_round_wrap, false, "round off the decimal 
v(d,s) to r digits behind the dot (if r < 0, before the dot)", args(1,5, 
batarg("",hge),batarg("v",hge),arg("d",int),arg("s",int),arg("r",bte))),
  command("calc", "second_interval", hge_dec2second_interval, false, "cast hge 
decimal to a second_interval", args(1,5, 
arg("",lng),arg("sc",int),arg("v",hge),arg("ek",int),arg("sk",int))),
+ command("batcalc", "second_interval", hge_batdec2second_interval, false, 
"cast hge decimal to a second_interval", args(1,5, 
batarg("",lng),arg("sc",int),batarg("v",hge),arg("ek",int),arg("sk",int))), 
  command("calc", "hge", nil_2dec_hge, false, "cast to dec(hge) and check for 
overflow", args(1,4, 
arg("",hge),arg("v",void),arg("digits",int),arg("scale",int))),
  command("batcalc", "hge", batnil_2dec_hge, false, "cast to dec(hge) and check 
for overflow", args(1,4, 
batarg("",hge),batarg("v",void),arg("digits",int),arg("scale",int))),
  command("batcalc", "hge", batnil_ce_2dec_hge, false, "cast to dec(hge) and 
check for overflow", args(1,5, 
batarg("",hge),batarg("v",void),arg("digits",int),arg("scale",int),batarg("r",bit))),
diff --git a/sql/backends/monet5/sql.h b/sql/backends/monet5/sql.h
--- a/sql/backends/monet5/sql.h
+++ b/sql/backends/monet5/sql.h
@@ -149,6 +149,7 @@ sql5_export str str_2dec_bte(bte *res, c
 sql5_export str batstr_2dec_bte(bat *res, const bat *val, const int *d, const 
int *sc);
 sql5_export str batstr_ce_2dec_bte(bat *res, const bat *val, const int *d, 
const int *sc, const bat *r);
 sql5_export str bte_dec2second_interval(lng *res, const int *sc, const bte 
*dec, const int *ek, const int *sk);
+sql5_export str bte_batdec2second_interval(bat *res, const int *sc, const bat 
*bid, const int *ek, const int *sk);
 
 sql5_export str nil_2dec_bte(bte *res, const void *val, const int *d, const 
int *sc);
 sql5_export str batnil_2dec_bte(bat *res, const bat *val, const int *d, const 
int *sc);
@@ -162,6 +163,7 @@ sql5_export str str_2dec_sht(sht *res, c
 sql5_export str batstr_2dec_sht(bat *res, const bat *val, const int *d, const 
int *sc);
 sql5_export str batstr_ce_2dec_sht(bat *res, const bat *val, const int *d, 
const int *sc, const bat *r);
 sql5_export str sht_dec2second_interval(lng *res, const int *sc, const sht 
*dec, const int *ek, const int *sk);
+sql5_export str sht_batdec2second_interval(bat *res, const int *sc, const bat 
*bid, const int *ek, const int *sk);
 
 sql5_export str nil_2dec_sht(sht *res, const void *val, const int *d, const 
int *sc);
 sql5_export str batnil_2dec_sht(bat *res, const bat *val, const int *d, const 
int *sc);
@@ -175,6 +177,7 @@ sql5_export str str_2dec_int(int *res, c
 sql5_export str batstr_2dec_int(bat *res, const bat *val, const int *d, const 
int *sc);
 sql5_export str batstr_ce_2dec_int(bat *res, const bat *val, const int *d, 
const int *sc, const bat *r);
 sql5_export str int_dec2second_interval(lng *res, const int *sc, const int 
*dec, const int *ek, const int *sk);
+sql5_export str int_batdec2second_interval(bat *res, const int *sc, const bat 
*bid, const int *ek, const int *sk);
 
 sql5_export str nil_2dec_int(int *res, const void *val, const int *d, const 
int *sc);
 sql5_export str batnil_2dec_int(bat *res, const bat *val, const int *d, const 
int *sc);
@@ -188,6 +191,7 @@ sql5_export str str_2dec_lng(lng *res, c
 sql5_export str batstr_2dec_lng(bat *res, const bat *val, const int *d, const 
int *sc);
 sql5_export str batstr_ce_2dec_lng(bat *res, const bat *val, const int *d, 
const int *sc, const bat *r);
 sql5_export str lng_dec2second_interval(lng *res, const int *sc, const lng 
*dec, const int *ek, const int *sk);
+sql5_export str lng_batdec2second_interval(bat *res, const int *sc, const bat 
*bid, const int *ek, const int *sk);
 
 sql5_export str nil_2dec_lng(lng *res, const void *val, const int *d, const 
int *sc);
 sql5_export str batnil_2dec_lng(bat *res, const bat *val, const int *d, const 
int *sc);
@@ -202,6 +206,7 @@ sql5_export str str_2dec_hge(hge *res, c
 sql5_export str batstr_2dec_hge(bat *res, const bat *val, const int *d, const 
int *sc);
 sql5_export str batstr_ce_2dec_hge(bat *res, const bat *val, const int *d, 
const int *sc, const bat *r);
 sql5_export str hge_dec2second_interval(lng *res, const int *sc, const hge 
*dec, const int *ek, const int *sk);
+sql5_export str hge_batdec2second_interval(bat *res, const int *sc, const bat 
*bid, const int *ek, const int *sk);
 
 sql5_export str nil_2dec_hge(hge *res, const void *val, const int *d, const 
int *sc);
 sql5_export str batnil_2dec_hge(bat *res, const bat *val, const int *d, const 
int *sc);
diff --git a/sql/backends/monet5/sql_round_impl.h 
b/sql/backends/monet5/sql_round_impl.h
--- a/sql/backends/monet5/sql_round_impl.h
+++ b/sql/backends/monet5/sql_round_impl.h
@@ -21,6 +21,7 @@
 #define batstr_2dec            FUN(batstr_2dec, TYPE)
 #define batstr_ce_2dec          FUN(batstr_ce_2dec, TYPE)
 #define dec2second_interval    FUN(TYPE, dec2second_interval)
+#define batdec2second_interval FUN(TYPE, batdec2second_interval)
 
 static inline TYPE
 dec_round_body_nonil(TYPE v, TYPE r)
@@ -452,7 +453,9 @@ dec2second_interval(lng *res, const int 
 
        (void) ek;
        (void) sk;
-       if (*sc < 3) {
+       if (ISNIL(TYPE)(*dec)) {
+               value = lng_nil;
+       } else if (*sc < 3) {
                int d = 3 - *sc;
                value *= scales[d];
        } else if (*sc > 3) {
@@ -466,6 +469,80 @@ dec2second_interval(lng *res, const int 
        return MAL_SUCCEED;
 }
 
+str
+batdec2second_interval(bat *res, const int *sc, const bat *bid, const int *ek, 
const int *sk)
+{
+       BAT *b, *dst;
+       BUN q = 0;
+       TYPE *restrict src;
+       BIG *restrict ret, multiplier = 1, divider = 1, offset = 0;
+
+       (void) ek;
+       (void) sk;
+       if ((b = BATdescriptor(*bid)) == NULL)
+               throw(SQL, "batcalc.batdec2second_interval", SQLSTATE(HY005) 
"Cannot access column descriptor");
+
+       q = BATcount(b);
+       if (!(dst = COLnew(b->hseqbase, TYPE_lng, q, TRANSIENT))) {
+               BBPunfix(b->batCacheid);
+               throw(SQL, "batcalc.batdec2second_interval", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+       }
+       src = Tloc(b, 0);
+       ret = Tloc(dst, 0);
+
+       if (*sc < 3) {
+               int d = 3 - *sc;
+               multiplier = scales[d];
+       } else if (*sc > 3) {
+               int d = *sc - 3;
+               lng rnd = scales[d] >> 1;
+
+               offset = rnd;
+               divider = scales[d];
+       }
+
+       if (*sc < 3) {
+               for (BUN i = 0 ; i < q ; i++) {
+                       if (ISNIL(TYPE)(src[i])) {
+                               ret[i] = lng_nil;
+                       } else {
+                               BIG next = (BIG) src[i];
+                               next *= multiplier;
+                               ret[i] = next;
+                       }
+               }
+       } else if (*sc > 3) {
+               for (BUN i = 0 ; i < q ; i++) {
+                       if (ISNIL(TYPE)(src[i])) {
+                               ret[i] = lng_nil;
+                       } else {
+                               BIG next = (BIG) src[i];
+                               next += offset;
+                               next /= divider;
+                               ret[i] = next;
+                       }
+               }
+       } else {
+               for (BUN i = 0 ; i < q ; i++) {
+                       if (ISNIL(TYPE)(src[i])) {
+                               ret[i] = lng_nil;
+                       } else {
+                               ret[i] = (BIG) src[i];
+                       }
+               }
+       }
+
+       BATsetcount(dst, q);
+       dst->tnil = b->tnil;
+       dst->tnonil = b->tnonil;
+       dst->tkey = BATcount(dst) <= 1;
+       dst->tsorted = BATcount(dst) <= 1;
+       dst->trevsorted = BATcount(dst) <= 1;
+       BBPunfix(b->batCacheid);
+       BBPkeepref(*res = dst->batCacheid);
+       return MAL_SUCCEED;
+}
+
 #undef dec_round_body_nonil
 #undef dec_round_body
 #undef dec_round_wrap
@@ -479,3 +556,4 @@ dec2second_interval(lng *res, const int 
 #undef batnil_2dec
 #undef batstr_2dec
 #undef dec2second_interval
+#undef batdec2second_interval
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to