Changeset: 0386cc50dd03 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0386cc50dd03
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
clients/Tests/exports.stable.out
monetdb5/modules/atoms/mtime.c
monetdb5/modules/atoms/mtime.mal
Branch: mtime
Log Message:
Implemented bulk versions of mtime.timestamp_{add,sub}_msec_interval.
This fixes bug 6695.
diffs (185 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
@@ -8928,6 +8928,8 @@ stdout of test 'MAL-signatures` in direc
[ "batmtime", "quarter", "command
batmtime.quarter(d:bat[:date]):bat[:int] ",
"MTIMEdate_extract_quarter_bulk;", "" ]
[ "batmtime", "sql_seconds", "command
batmtime.sql_seconds(d:bat[:daytime]):bat[:int] ",
"MTIMEdaytime_extract_sql_seconds_bulk;", "" ]
[ "batmtime", "sql_seconds", "command
batmtime.sql_seconds(d:bat[:timestamp]):bat[:int] ",
"MTIMEtimestamp_sql_seconds_bulk;", "" ]
+[ "batmtime", "timestamp_add_msec_interval", "command
batmtime.timestamp_add_msec_interval(t:bat[:timestamp],
ms:bat[:lng]):bat[:timestamp] ",
"MTIMEtimestamp_add_msec_interval_bulk;", "" ]
+[ "batmtime", "timestamp_sub_msec_interval", "command
batmtime.timestamp_sub_msec_interval(t:bat[:timestamp],
ms:bat[:lng]):bat[:timestamp] ",
"MTIMEtimestamp_sub_msec_interval_bulk;", "" ]
[ "batmtime", "year", "command batmtime.year(d:bat[:date]):bat[:int] ",
"MTIMEdate_extract_year_bulk;", "" ]
[ "batpcre", "replace", "command batpcre.replace(orig:bat[:str],
pat:str, repl:str, flag:str):bat[:str] ", "PCREreplace_bat_wrap;",
"" ]
[ "batpcre", "replace_first", "command
batpcre.replace_first(orig:bat[:str], pat:str, repl:str, flag:str):bat[:str] ",
"PCREreplacefirst_bat_wrap;", "" ]
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
@@ -12656,6 +12656,8 @@ stdout of test 'MAL-signatures` in direc
[ "batmtime", "quarter", "command
batmtime.quarter(d:bat[:date]):bat[:int] ",
"MTIMEdate_extract_quarter_bulk;", "" ]
[ "batmtime", "sql_seconds", "command
batmtime.sql_seconds(d:bat[:daytime]):bat[:int] ",
"MTIMEdaytime_extract_sql_seconds_bulk;", "" ]
[ "batmtime", "sql_seconds", "command
batmtime.sql_seconds(d:bat[:timestamp]):bat[:int] ",
"MTIMEtimestamp_sql_seconds_bulk;", "" ]
+[ "batmtime", "timestamp_add_msec_interval", "command
batmtime.timestamp_add_msec_interval(t:bat[:timestamp],
ms:bat[:lng]):bat[:timestamp] ",
"MTIMEtimestamp_add_msec_interval_bulk;", "" ]
+[ "batmtime", "timestamp_sub_msec_interval", "command
batmtime.timestamp_sub_msec_interval(t:bat[:timestamp],
ms:bat[:lng]):bat[:timestamp] ",
"MTIMEtimestamp_sub_msec_interval_bulk;", "" ]
[ "batmtime", "year", "command batmtime.year(d:bat[:date]):bat[:int] ",
"MTIMEdate_extract_year_bulk;", "" ]
[ "batpcre", "replace", "command batpcre.replace(orig:bat[:str],
pat:str, repl:str, flag:str):bat[:str] ", "PCREreplace_bat_wrap;",
"" ]
[ "batpcre", "replace_first", "command
batpcre.replace_first(orig:bat[:str], pat:str, repl:str, flag:str):bat[:str] ",
"PCREreplacefirst_bat_wrap;", "" ]
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
@@ -1529,6 +1529,8 @@ str MTIMEtime_sub_msec_interval(daytime
str MTIMEtime_to_str(str *ret, const daytime *d, const char *const *format);
str MTIMEtimestamp_add_month_interval(timestamp *ret, const timestamp *t,
const int *m);
str MTIMEtimestamp_add_msec_interval(timestamp *ret, const timestamp *t, const
lng *ms);
+str MTIMEtimestamp_add_msec_interval(timestamp *ret, const timestamp *v1,
const lng *v2);
+str MTIMEtimestamp_add_msec_interval_bulk(bat *ret, const bat *bid1, const bat
*bid2);
str MTIMEtimestamp_century(int *ret, const timestamp *t);
str MTIMEtimestamp_day(int *ret, const timestamp *t);
str MTIMEtimestamp_decade(int *ret, const timestamp *t);
@@ -1553,6 +1555,8 @@ str MTIMEtimestamp_sql_seconds(int *ret,
str MTIMEtimestamp_sql_seconds_bulk(bat *ret, const bat *bid);
str MTIMEtimestamp_sub_month_interval(timestamp *ret, const timestamp *t,
const int *m);
str MTIMEtimestamp_sub_msec_interval(timestamp *ret, const timestamp *t, const
lng *ms);
+str MTIMEtimestamp_sub_msec_interval(timestamp *ret, const timestamp *v1,
const lng *v2);
+str MTIMEtimestamp_sub_msec_interval_bulk(bat *ret, const bat *bid1, const bat
*bid2);
str MTIMEtimestamp_timestamp(timestamp *dst, const timestamp *src);
str MTIMEtimestamp_to_str(str *ret, const timestamp *d, const char *const
*format);
str MTIMEtimestamp_year(int *ret, const timestamp *t);
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
@@ -1195,6 +1195,82 @@ NAMEBULK(bat *ret, const bat *bid1, cons
#define DATEDIFF(d1, d2) (date_countdays(d1) - date_countdays(d2))
func2(MTIMEdate_diff, MTIMEdate_diff_bulk, "diff", date, date, int, DATEDIFF)
+#define func2chk(NAME, NAMEBULK, MALFUNC, INTYPE1, INTYPE2, OUTTYPE, FUNC)
\
+mal_export str NAME(OUTTYPE *ret, const INTYPE1 *v1, const INTYPE2 *v2); \
+mal_export str NAMEBULK(bat *ret, const bat *bid1, const bat *bid2); \
+str
\
+NAME(OUTTYPE *ret, const INTYPE1 *v1, const INTYPE2 *v2)
\
+{
\
+ if (is_##INTYPE1##_nil(*v1) || is_##INTYPE2##_nil(*v2))
\
+ *ret = OUTTYPE##_nil;
\
+ else {
\
+ *ret = FUNC(*v1, *v2);
\
+ if (is_##OUTTYPE##_nil(*ret))
\
+ throw(MAL, "mtime." MALFUNC,
\
+ SQLSTATE(22003) "overflow in calculation");
\
+ }
\
+ return MAL_SUCCEED;
\
+}
\
+str
\
+NAMEBULK(bat *ret, const bat *bid1, const bat *bid2)
\
+{
\
+ BAT *b1, *b2, *bn;
\
+ BUN n;
\
+ const INTYPE1 *src1;
\
+ const INTYPE2 *src2;
\
+ OUTTYPE *dst;
\
+
\
+ b1 = BATdescriptor(*bid1);
\
+ b2 = BATdescriptor(*bid2);
\
+ if (b1 == NULL || b2 == NULL) {
\
+ if (b1)
\
+ BBPunfix(b1->batCacheid);
\
+ if (b2)
\
+ BBPunfix(b2->batCacheid);
\
+ throw(MAL, "batmtime." MALFUNC,
\
+ SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
\
+ }
\
+ n = BATcount(b1);
\
+ if (n != BATcount(b2)) {
\
+ BBPunfix(b1->batCacheid);
\
+ BBPunfix(b2->batCacheid);
\
+ throw(MAL, "batmtime." MALFUNC, "inputs not the same size");
\
+ }
\
+ if ((bn = COLnew(b1->hseqbase, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL)
{ \
+ BBPunfix(b1->batCacheid);
\
+ BBPunfix(b2->batCacheid);
\
+ throw(MAL, "batmtime." MALFUNC, SQLSTATE(HY001)
MAL_MALLOC_FAIL); \
+ }
\
+ src1 = Tloc(b1, 0);
\
+ src2 = Tloc(b2, 0);
\
+ dst = Tloc(bn, 0);
\
+ bn->tnil = false;
\
+ for (BUN i = 0; i < n; i++) {
\
+ if (is_##INTYPE1##_nil(src1[i]) || is_##INTYPE2##_nil(src2[i]))
{ \
+ dst[i] = OUTTYPE##_nil;
\
+ bn->tnil = true;
\
+ } else {
\
+ dst[i] = FUNC(src1[i], src2[i]);
\
+ if (is_##OUTTYPE##_nil(dst[i])) {
\
+ BBPunfix(b1->batCacheid);
\
+ BBPunfix(b2->batCacheid);
\
+ BBPreclaim(bn);
\
+ throw(MAL, "batmtime." MALFUNC,
\
+ SQLSTATE(22003) "overflow in
calculation"); \
+ }
\
+ }
\
+ }
\
+ bn->tnonil = !bn->tnil;
\
+ BATsetcount(bn, n);
\
+ bn->tsorted = n < 2;
\
+ bn->trevsorted = n < 2;
\
+ bn->tkey = false;
\
+ BBPunfix(b1->batCacheid);
\
+ BBPunfix(b2->batCacheid);
\
+ BBPkeepref(*ret = bn->batCacheid);
\
+ return MAL_SUCCEED;
\
+}
+
str
MTIMEdate_sub_msec_interval(date *ret, const date *d, const lng *ms)
{
@@ -1223,33 +1299,10 @@ MTIMEdate_add_msec_interval(date *ret, c
return MAL_SUCCEED;
}
-str
-MTIMEtimestamp_sub_msec_interval(timestamp *ret, const timestamp *t, const lng
*ms)
-{
- if (is_timestamp_nil(*t) || is_lng_nil(*ms))
- *ret = timestamp_nil;
- else {
- *ret = timestamp_add_usec(*t, -*ms * 1000);
- if (is_timestamp_nil(*ret))
- throw(MAL, "mtime.timestamp_sub_msec_interval",
- SQLSTATE(22003) "overflow in calculation");
- }
- return MAL_SUCCEED;
-}
-
-str
-MTIMEtimestamp_add_msec_interval(timestamp *ret, const timestamp *t, const lng
*ms)
-{
- if (is_timestamp_nil(*t) || is_lng_nil(*ms))
- *ret = timestamp_nil;
- else {
- *ret = timestamp_add_usec(*t, *ms * 1000);
- if (is_timestamp_nil(*ret))
- throw(MAL, "mtime.timestamp_add_msec_interval",
- SQLSTATE(22003) "overflow in calculation");
- }
- return MAL_SUCCEED;
-}
+#define TSSUBMS(ts, ms) timestamp_add_usec((ts), -(ms) * 1000)
+#define TSADDMS(ts, ms) timestamp_add_usec((ts), (ms) * 1000)
+func2chk(MTIMEtimestamp_sub_msec_interval,
MTIMEtimestamp_sub_msec_interval_bulk, "timestamp_sub_msec_interval",
timestamp, lng, timestamp, TSSUBMS)
+func2chk(MTIMEtimestamp_add_msec_interval,
MTIMEtimestamp_add_msec_interval_bulk, "timestamp_add_msec_interval",
timestamp, lng, timestamp, TSADDMS)
str
MTIMEtimestamp_sub_month_interval(timestamp *ret, const timestamp *t, const
int *m)
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
@@ -292,8 +292,12 @@ address MTIMEdate_add_msec_interval;
command timestamp_sub_msec_interval(t:timestamp,ms:lng):timestamp
address MTIMEtimestamp_sub_msec_interval;
+command
batmtime.timestamp_sub_msec_interval(t:bat[:timestamp],ms:bat[:lng]):bat[:timestamp]
+address MTIMEtimestamp_sub_msec_interval_bulk;
command timestamp_add_msec_interval(t:timestamp,ms:lng):timestamp
address MTIMEtimestamp_add_msec_interval;
+command
batmtime.timestamp_add_msec_interval(t:bat[:timestamp],ms:bat[:lng]):bat[:timestamp]
+address MTIMEtimestamp_add_msec_interval_bulk;
command timestamp_sub_month_interval(t:timestamp,s:int):timestamp
address MTIMEtimestamp_sub_month_interval
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list