Changeset: 2fd79f44be9c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2fd79f44be9c
Modified Files:
        monetdb5/modules/atoms/mtime.c
        monetdb5/modules/atoms/mtime.mal
Branch: mtime
Log Message:

Bulk version of mtime.sql_seconds(:timestamp).


diffs (86 lines):

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
@@ -1001,6 +1001,7 @@ mal_export str MTIMEtimestamp_day(int *r
 mal_export str MTIMEtimestamp_hours(int *ret, const timestamp *t);
 mal_export str MTIMEtimestamp_minutes(int *ret, const timestamp *t);
 mal_export str MTIMEtimestamp_sql_seconds(int *ret, const timestamp *t);
+mal_export str MTIMEtimestamp_sql_seconds_bulk(bat *ret, bat *bid);
 mal_export str MTIMEsql_year(int *ret, const int *months);
 mal_export str MTIMEsql_month(int *ret, const int *months);
 mal_export str MTIMEsql_day(lng *ret, const lng *msecs);
@@ -1506,7 +1507,7 @@ MTIMEdaytime_extract_minutes_bulk(bat *r
 str
 MTIMEdaytime_extract_sql_seconds(int *ret, const daytime *t)
 {
-       *ret = is_daytime_nil(*t) ? int_nil : (int) (*t % 60000000) / 1000;
+       *ret = is_daytime_nil(*t) ? int_nil : (int) ((*t % 60000000) / 1000);
        return MAL_SUCCEED;
 }
 
@@ -1533,7 +1534,7 @@ MTIMEdaytime_extract_sql_seconds_bulk(ba
                        m[i] = int_nil;
                        bn->tnil = true;
                } else {
-                       m[i] = (int) (d[i] % 60000000) / 1000;
+                       m[i] = (int) ((d[i] % 60000000) / 1000);
                }
        }
        bn->tnonil = !bn->tnil;
@@ -1677,7 +1678,43 @@ MTIMEtimestamp_minutes(int *ret, const t
 str
 MTIMEtimestamp_sql_seconds(int *ret, const timestamp *t)
 {
-       *ret = is_timestamp_nil(*t) ? int_nil : (int) (ts_time(*t) % 60000000) 
/ 1000;
+       *ret = is_timestamp_nil(*t) ? int_nil : (int) ((ts_time(*t) % 60000000) 
/ 1000);
+       return MAL_SUCCEED;
+}
+
+str
+MTIMEtimestamp_sql_seconds_bulk(bat *ret, bat *bid)
+{
+       BAT *b, *bn;
+       BUN n;
+       const timestamp *t;
+       int *m;
+
+       if ((b = BATdescriptor(*bid)) == NULL)
+               throw(MAL, "batmtime.sql_seconds", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
+       n = BATcount(b);
+       if ((bn = COLnew(b->hseqbase, TYPE_int, n, TRANSIENT)) == NULL) {
+               BBPunfix(b->batCacheid);
+               throw(MAL, "batmtime.sql_seconds", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+       }
+       t = Tloc(b, 0);
+       m = Tloc(bn, 0);
+       bn->tnil = false;
+       for (BUN i = 0; i < n; i++) {
+               if (is_timestamp_nil(t[i])) {
+                       m[i] = int_nil;
+                       bn->tnil = true;
+               } else {
+                       m[i] = (int) ((ts_time(t[i]) % 60000000) / 1000);
+               }
+       }
+       bn->tnonil = !bn->tnil;
+       BATsetcount(bn, n);
+       bn->tsorted = n < 2;
+       bn->trevsorted = n < 2;
+       bn->tkey = false;
+       BBPunfix(b->batCacheid);
+       BBPkeepref(*ret = bn->batCacheid);
        return MAL_SUCCEED;
 }
 
diff --git a/monetdb5/modules/atoms/mtime.mal b/monetdb5/modules/atoms/mtime.mal
--- a/monetdb5/modules/atoms/mtime.mal
+++ b/monetdb5/modules/atoms/mtime.mal
@@ -584,6 +584,8 @@ address MTIMEtimestamp_minutes;
 # address MTIMEtimestamp_seconds;
 command sql_seconds(t:timestamp):int
 address MTIMEtimestamp_sql_seconds;
+command batmtime.sql_seconds(d:bat[:timestamp]):bat[:int]
+address MTIMEtimestamp_sql_seconds_bulk;
 # command milliseconds(t:timestamp):int
 # address MTIMEtimestamp_milliseconds;
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to