Changeset: f1d569421968 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f1d569421968
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/modules/atoms/blob.c
        monetdb5/modules/atoms/blob.mal
        monetdb5/modules/atoms/mtime.c
        monetdb5/modules/atoms/mtime.mal
        sql/test/miscellaneous/Tests/simple_selects.sql
        sql/test/miscellaneous/Tests/simple_selects.stable.out
Branch: mbedded
Log Message:

more merging fun ...


diffs (truncated from 592 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -951,6 +951,7 @@ BUN BLOBhash(const blob *b);
 void BLOBheap(Heap *heap, size_t capacity);
 size_t BLOBlength(const blob *p);
 str BLOBnitems(int *ret, blob **b);
+str BLOBnitems_bulk(bat *ret, const bat *bid);
 const blob *BLOBnull(void);
 str BLOBprelude(void *ret);
 var_t BLOBput(Heap *h, var_t *bun, const blob *val);
@@ -1598,7 +1599,8 @@ str MTIMEdate_extract_weekofyear(int *re
 str MTIMEdate_extract_weekofyear_bulk(bat *ret, const bat *bid);
 str MTIMEdate_extract_year(int *ret, const date *src);
 str MTIMEdate_extract_year_bulk(bat *ret, const bat *bid);
-str MTIMEdate_fromstr(date *ret, const char *const *s);
+str MTIMEdate_fromstr(date *ret, const const char *const *src);
+str MTIMEdate_fromstr_bulk(bat *ret, const bat *bid);
 str MTIMEdate_sub_msec_interval(date *ret, const date *v1, const lng *v2);
 str MTIMEdate_sub_msec_interval_bulk(bat *ret, const bat *bid1, const bat 
*bid2);
 str MTIMEdate_submonths(date *ret, const date *v1, const int *v2);
@@ -1615,9 +1617,10 @@ str MTIMEdaytime_extract_minutes(int *re
 str MTIMEdaytime_extract_minutes_bulk(bat *ret, const bat *bid);
 str MTIMEdaytime_extract_sql_seconds(int *ret, const daytime *src);
 str MTIMEdaytime_extract_sql_seconds_bulk(bat *ret, const bat *bid);
-str MTIMEdaytime_fromseconds(daytime *ret, const lng *secs);
-str MTIMEdaytime_fromseconds_bulk(bat *ret, bat *bid);
-str MTIMEdaytime_fromstr(daytime *ret, const char *const *s);
+str MTIMEdaytime_fromseconds(daytime *ret, const const lng *src);
+str MTIMEdaytime_fromseconds_bulk(bat *ret, const bat *bid);
+str MTIMEdaytime_fromstr(daytime *ret, const const char *const *src);
+str MTIMEdaytime_fromstr_bulk(bat *ret, const bat *bid);
 str MTIMElocal_timezone_msec(lng *ret);
 str MTIMEseconds_since_epoch(int *ret, const timestamp *src);
 str MTIMEseconds_since_epoch_bulk(bat *ret, const bat *bid);
@@ -1667,7 +1670,8 @@ str MTIMEtimestamp_frommsec(timestamp *r
 str MTIMEtimestamp_frommsec_bulk(bat *ret, const bat *bid);
 str MTIMEtimestamp_fromsecond(timestamp *ret, const int *src);
 str MTIMEtimestamp_fromsecond_bulk(bat *ret, const bat *bid);
-str MTIMEtimestamp_fromstr(timestamp *ret, const char *const *s);
+str MTIMEtimestamp_fromstr(timestamp *ret, const const char *const *src);
+str MTIMEtimestamp_fromstr_bulk(bat *ret, const bat *bid);
 str MTIMEtimestamp_hours(int *ret, const timestamp *src);
 str MTIMEtimestamp_hours_bulk(bat *ret, const bat *bid);
 str MTIMEtimestamp_minutes(int *ret, const timestamp *src);
diff --git a/monetdb5/modules/atoms/blob.c b/monetdb5/modules/atoms/blob.c
--- a/monetdb5/modules/atoms/blob.c
+++ b/monetdb5/modules/atoms/blob.c
@@ -45,6 +45,7 @@ mal_export size_t BLOBlength(const blob 
 mal_export void BLOBheap(Heap *heap, size_t capacity);
 mal_export str BLOBtoblob(blob **retval, str *s);
 mal_export str BLOBnitems(int *ret, blob **b);
+mal_export str BLOBnitems_bulk(bat *ret, const bat *bid);
 mal_export int BLOBget(Heap *h, int *bun, int *l, blob **val);
 mal_export blob * BLOBread(blob *a, stream *s, size_t cnt);
 mal_export gdk_return BLOBwrite(const blob *a, stream *s, size_t cnt);
@@ -180,16 +181,59 @@ BLOBput(Heap *h, var_t *bun, const blob 
        return *bun;
 }
 
+static inline int 
+blob_nitems(blob *b)
+{
+       if (is_blob_nil(b))
+               return int_nil;
+       assert(b->nitems <INT_MAX);
+       return (int) b->nitems;
+}
+
 str
 BLOBnitems(int *ret, blob **b)
 {
-       if (is_blob_nil(*b)) {
-               *ret = int_nil;
-               return MAL_SUCCEED;
+       *ret = blob_nitems(*b);
+       return MAL_SUCCEED;
+}
+
+str
+BLOBnitems_bulk(bat *ret, const bat *bid)
+{
+       BAT *b = NULL, *bn = NULL;
+       BUN n, p, q;
+       int *dst, i = 0;
+       str msg = MAL_SUCCEED;
+       BATiter bi;
+
+       if ((b = BATdescriptor(*bid)) == NULL)  {
+               throw(MAL, "blob.nitems_bulk", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
+               goto bailout;
        }
-       assert((*b)->nitems <INT_MAX);
-       *ret = (int) (*b)->nitems;
-       return MAL_SUCCEED;
+       n = BATcount(b);
+       if ((bn = COLnew(b->hseqbase, TYPE_int, n, TRANSIENT)) == NULL) {
+               msg = createException(MAL, "blob.nitems_bulk", SQLSTATE(HY013) 
MAL_MALLOC_FAIL); 
+               goto bailout;
+       }
+       dst = Tloc(bn, 0);
+       bi = bat_iterator(b);
+       BATloop(b, p, q) {
+               blob *next = BUNtvar(bi, p);
+               dst[i++] = blob_nitems(next);
+       }
+       bn->tnonil = b->tnonil;
+       bn->tnil = b->tnil;
+       BATsetcount(bn, n);
+       bn->tsorted = bn->trevsorted = n < 2;
+       bn->tkey = false;
+bailout:
+       if (b)
+               BBPunfix(b->batCacheid);
+       if (msg && bn)
+               BBPreclaim(bn);
+       else if (bn)
+               BBPkeepref(*ret = bn->batCacheid);
+       return msg;
 }
 
 str
@@ -363,14 +407,15 @@ BLOBblob_fromstr(blob **b, const char **
 }
 
 #include "mel.h"
-mel_atom blob_init_atoms[] = {
+static mel_atom blob_init_atoms[] = {
  { .name="blob", .tostr=(fptr)&BLOBtostr, .fromstr=(fptr)&BLOBfromstr, 
.cmp=(fptr)&BLOBcmp, .hash=(fptr)&BLOBhash, .null=(fptr)&BLOBnull, 
.read=(fptr)&BLOBread, .write=(fptr)&BLOBwrite, .put=(fptr)&BLOBput, 
.del=(fptr)&BLOBdel, .length=(fptr)&BLOBlength, .heap=(fptr)&BLOBheap, },  { 
.cmp=NULL } 
 };
-mel_func blob_init_funcs[] = {
+static mel_func blob_init_funcs[] = {
  command("blob", "blob", BLOBblob_blob, false, "Noop routine.", args(1,2, 
arg("",blob),arg("s",blob))),
  command("blob", "blob", BLOBblob_fromstr, false, "", args(1,2, 
arg("",blob),arg("s",str))),
  command("blob", "toblob", BLOBtoblob, false, "store a string as a blob.", 
args(1,2, arg("",blob),arg("v",str))),
  command("blob", "nitems", BLOBnitems, false, "get the number of bytes in this 
blob.", args(1,2, arg("",int),arg("b",blob))),
+ command("batblob", "nitems", BLOBnitems_bulk, false, "", args(1,2, 
batarg("",int),batarg("b",blob))),
  command("blob", "prelude", BLOBprelude, false, "", args(1,1, arg("",void))),
  command("calc", "blob", BLOBblob_blob, false, "", args(1,2, 
arg("",blob),arg("b",blob))),
  command("calc", "blob", BLOBblob_fromstr, false, "", args(1,2, 
arg("",blob),arg("s",str))),
diff --git a/monetdb5/modules/atoms/blob.mal b/monetdb5/modules/atoms/blob.mal
--- a/monetdb5/modules/atoms/blob.mal
+++ b/monetdb5/modules/atoms/blob.mal
@@ -4,6 +4,7 @@
 #
 # Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V.
 
+module batblob;
 module blob;
 
 atom blob;
@@ -38,6 +39,8 @@ comment "store a string as a blob.";
 command nitems(b:blob):int
 address BLOBnitems
 comment "get the number of bytes in this blob.";
+command batblob.nitems(b:bat[:blob]):bat[:int]
+address BLOBnitems_bulk;
 
 command prelude() :void
 address BLOBprelude;
diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -42,12 +42,6 @@ extern char *strptime(const char *, cons
 mal_export str MTIMEcurrent_date(date *ret);
 mal_export str MTIMEcurrent_time(daytime *ret);
 mal_export str MTIMEcurrent_timestamp(timestamp *ret);
-
-mal_export str MTIMEdate_fromstr(date *ret, const char *const *s);
-mal_export str MTIMEtimestamp_fromstr(timestamp *ret, const char *const *s);
-mal_export str MTIMEdaytime_fromstr(daytime *ret, const char *const *s);
-mal_export str MTIMEdaytime_fromseconds(daytime *ret, const lng *secs);
-mal_export str MTIMEdaytime_fromseconds_bulk(bat *ret, bat *bid);
 mal_export str MTIMElocal_timezone_msec(lng *ret);
 
 str
@@ -73,46 +67,61 @@ MTIMEcurrent_timestamp(timestamp *ret)
 
 #define COPYFLAGS      do { bn->tsorted = b->tsorted; bn->trevsorted = 
b->trevsorted; } while (0)
 #define SETFLAGS       do { bn->tsorted = bn->trevsorted = n < 2; } while (0)
-#define func1(NAME, NAMEBULK, MALFUNC, INTYPE, OUTYPE, FUNC, SETFLAGS) \
+#define func1(NAME, NAMEBULK, MALFUNC, INTYPE, OUTYPE, FUNC, SETFLAGS, 
FUNC_CALL)      \
 mal_export str NAME(OUTYPE *ret, const INTYPE *src);                           
        \
 mal_export str NAMEBULK(bat *ret, const bat *bid);                             
                \
 str                                                                            
                                                                \
 NAME(OUTYPE *ret, const INTYPE *src)                                           
                        \
 {                                                                              
                                                                \
-       *ret = FUNC(*src);                                                      
                                                \
-       return MAL_SUCCEED;                                                     
                                                \
+       str msg = MAL_SUCCEED;                                                  
                                        \
+       do {                                                                    
                                                        \
+               FUNC_CALL(FUNC, (*ret), *src);                                  
                                \
+       } while (0);                                                            
                                                \
+       return msg;                                                             
                                                        \
 }                                                                              
                                                                \
 str                                                                            
                                                                \
 NAMEBULK(bat *ret, const bat *bid)                                             
                                \
 {                                                                              
                                                                \
-       BAT *b, *bn;                                                            
                                                \
+       BAT *b = NULL, *bn = NULL;                                              
                                        \
        BUN n;                                                                  
                                                        \
        const INTYPE *src;                                                      
                                                \
        OUTYPE *dst;                                                            
                                                \
+       str msg = MAL_SUCCEED;                                                  
                                        \
                                                                                
                                                                \
-       if ((b = BATdescriptor(*bid)) == NULL)                                  
                        \
-               throw(MAL, "batmtime." MALFUNC,                                 
                                \
+       if ((b = BATdescriptor(*bid)) == NULL)  {                               
                        \
+               msg = createException(MAL, "batmtime." MALFUNC,                 
                \
                          SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);              
                        \
+               goto bailout;                                                   
                                                \
+       }                                                                       
                                                                \
        n = BATcount(b);                                                        
                                                \
        if ((bn = COLnew(b->hseqbase, TYPE_##OUTYPE, n, TRANSIENT)) == NULL) { \
-               BBPunfix(b->batCacheid);                                        
                                        \
-               throw(MAL, "batmtime." MALFUNC, SQLSTATE(HY013) 
MAL_MALLOC_FAIL); \
+               msg = createException(MAL, "batmtime." MALFUNC,                 
                \
+                         SQLSTATE(HY013) MAL_MALLOC_FAIL);                     
                        \
+               goto bailout;                                                   
                                                \
        }                                                                       
                                                                \
        src = Tloc(b, 0);                                                       
                                                \
        dst = Tloc(bn, 0);                                                      
                                                \
        for (BUN i = 0; i < n; i++) {                                           
                                \
-               dst[i] = FUNC(src[i]);                                          
                                        \
+               FUNC_CALL(FUNC, (dst[i]), src[i]);                              
                                \
        }                                                                       
                                                                \
        bn->tnonil = b->tnonil;                                                 
                                        \
        bn->tnil = b->tnil;                                                     
                                                \
        BATsetcount(bn, n);                                                     
                                                \
        SETFLAGS;                                                               
                                                        \
        bn->tkey = false;                                                       
                                                \
-       BBPunfix(b->batCacheid);                                                
                                        \
-       BBPkeepref(*ret = bn->batCacheid);                                      
                                \
-       return MAL_SUCCEED;                                                     
                                                \
+bailout:                                                                       
                                                        \
+       if (b)                                                                  
                                                        \
+               BBPunfix(b->batCacheid);                                        
                                        \
+       if (msg && bn)                                                          
                                                \
+               BBPreclaim(bn);                                                 
                                                \
+       else if (bn)                                                            
                                                \
+               BBPkeepref(*ret = bn->batCacheid);                              
                                \
+       return msg;                                                             
                                                        \
 }
 
+#define func1_noexcept(FUNC, RET, PARAM) RET = FUNC(PARAM)
+#define func1_except(FUNC, RET, PARAM) msg = FUNC(&RET, PARAM); if (msg) break;
+
 #define func2(NAME, NAMEBULK, MALFUNC, INTYPE1, INTYPE2, OUTTYPE, FUNC, 
FUNC_CALL)     \
 mal_export str NAME(OUTTYPE *ret, const INTYPE1 *v1, const INTYPE2 *v2); \
 mal_export str NAMEBULK(bat *ret, const bat *bid1, const bat *bid2);   \
@@ -128,7 +137,7 @@ NAME(OUTTYPE *ret, const INTYPE1 *v1, co
 str                                                                            
                                                                \
 NAMEBULK(bat *ret, const bat *bid1, const bat *bid2)                           
        \
 {                                                                              
                                                                \
-       BAT *b1, *b2, *bn;                                                      
                                                \
+       BAT *b1 = NULL, *b2 = NULL, *bn = NULL;                                 
                        \
        BUN n;                                                                  
                                                        \
        const INTYPE1 *src1;                                                    
                                        \
        const INTYPE2 *src2;                                                    
                                        \
@@ -138,25 +147,17 @@ NAMEBULK(bat *ret, const bat *bid1, cons
        b1 = BATdescriptor(*bid1);                                              
                                        \
        b2 = BATdescriptor(*bid2);                                              
                                        \
        if (b1 == NULL || b2 == NULL) {                                         
                                \
-               if (b1)                                                         
                                                        \
-                       BBPunfix(b1->batCacheid);                               
                                        \
-               if (b2)                                                         
                                                        \
-                       BBPunfix(b2->batCacheid);                               
                                        \
                msg = createException(MAL, "batmtime." MALFUNC,                 
                \
                          SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);              
                        \
                goto bailout;                                                   
                                                \
        }                                                                       
                                                                \
        n = BATcount(b1);                                                       
                                                \
        if (n != BATcount(b2)) {                                                
                                        \
-               BBPunfix(b1->batCacheid);                                       
                                        \
-               BBPunfix(b2->batCacheid);                                       
                                        \
                msg = createException(MAL, "batmtime." MALFUNC,                 
                \
                          "inputs not the same size");                          
                                \
                goto bailout;                                                   
                                                \
        }                                                                       
                                                                \
        if ((bn = COLnew(b1->hseqbase, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) 
{ \
-               BBPunfix(b1->batCacheid);                                       
                                        \
-               BBPunfix(b2->batCacheid);                                       
                                        \
                msg = createException(MAL, "batmtime." MALFUNC,                 
                \
                          SQLSTATE(HY013) MAL_MALLOC_FAIL);                     
                        \
                goto bailout;                                                   
                                                \
@@ -285,14 +286,14 @@ func2chk(MTIMEtimestamp_add_month_interv
 static inline daytime
 time_sub_msec_interval(const daytime t, const lng ms)
 {
-       if (is_daytime_nil(t) || is_lng_nil(ms))
+       if (is_lng_nil(ms))
                return daytime_nil;
        return daytime_add_usec_modulo(t, -ms * 1000);
 }
 static inline daytime
 time_add_msec_interval(const daytime t, const lng ms)
 {
-       if (is_daytime_nil(t) || is_lng_nil(ms))
+       if (is_lng_nil(ms))
                return daytime_nil;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to