Changeset: a85d29d50b35 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a85d29d50b35
Modified Files:
sql/backends/monet5/sql_time.c
sql/test/SQLancer/Tests/sqlancer04.sql
sql/test/SQLancer/Tests/sqlancer04.stable.err
sql/test/SQLancer/Tests/sqlancer04.stable.out
Branch: Oct2020
Log Message:
Making SQLancer happy. Test for overflows while converting from interval second
to time type
diffs (189 lines):
diff --git a/sql/backends/monet5/sql_time.c b/sql/backends/monet5/sql_time.c
--- a/sql/backends/monet5/sql_time.c
+++ b/sql/backends/monet5/sql_time.c
@@ -109,8 +109,8 @@ bailout:
return msg;
}
-static inline daytime
-second_interval_2_daytime_imp(lng next,
+static inline str
+second_interval_2_daytime_imp(daytime *res, lng next,
#ifdef HAVE_HGE
hge shift, hge divider, hge multiplier
#else
@@ -118,7 +118,18 @@ lng shift, lng divider, lng multiplier
#endif
) {
daytime d = daytime_add_usec(daytime_create(0, 0, 0, 0), next * 1000);
- return daytime_2time_daytime_imp(d, shift, divider, multiplier);
+ if (is_daytime_nil(d)) {
+ str msg;
+ size_t len = 0;
+ char *str_val = NULL;
+ if (BATatoms[TYPE_lng].atomToStr(&str_val, &len, &next, false)
< 0)
+ return createException(SQL,
"batcalc.second_interval_2_daytime", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ msg = createException(SQL, "batcalc.second_interval_2_daytime",
SQLSTATE(22003) "Overflow in convertion of second interval '%s' to time",
str_val);
+ GDKfree(str_val);
+ return msg;
+ }
+ *res = daytime_2time_daytime_imp(d, shift, divider, multiplier);
+ return MAL_SUCCEED;
}
str
@@ -172,7 +183,7 @@ second_interval_2_daytime(Client cntxt,
if (is_a_bat) {
oid off = b->hseqbase;
lng *restrict vals = (lng*) Tloc(b, 0);
- for (BUN i = 0 ; i < q ; i++) {
+ for (BUN i = 0 ; i < q && !msg; i++) {
BUN p = (BUN) (canditer_next(&ci) - off);
lng next = vals[p];
@@ -180,12 +191,15 @@ second_interval_2_daytime(Client cntxt,
ret[i] = daytime_nil;
nils = true;
} else {
- ret[i] = second_interval_2_daytime_imp(next,
shift, divider, multiplier);
+ msg = second_interval_2_daytime_imp(&(ret[i]),
next, shift, divider, multiplier);
}
}
} else {
lng next = *(lng*)getArgReference(stk, pci, 1);
- *ret = is_lng_nil(next) ? daytime_nil :
second_interval_2_daytime_imp(next, shift, divider, multiplier);
+ if (is_lng_nil(next))
+ *ret = daytime_nil;
+ else
+ msg = second_interval_2_daytime_imp(ret, next, shift,
divider, multiplier);
}
bailout:
diff --git a/sql/test/SQLancer/Tests/sqlancer04.sql
b/sql/test/SQLancer/Tests/sqlancer04.sql
--- a/sql/test/SQLancer/Tests/sqlancer04.sql
+++ b/sql/test/SQLancer/Tests/sqlancer04.sql
@@ -277,3 +277,53 @@ ROLLBACK;
SELECT CASE WHEN 3 THEN cot(COALESCE(3, 4)) END FROM (values(1),(2)) as t0(c0);
select coalesce(-1129107763, '1415606329') from (values(1),(2)) as t0(c0);
+
+START TRANSACTION;
+CREATE TABLE "sys"."t0" ("c0" TIME NOT NULL, CONSTRAINT "t0_c0_pkey" PRIMARY
KEY ("c0"));
+COPY 15 RECORDS INTO "sys"."t0" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+15:11:18
+01:20:22
+13:28:53
+11:33:19
+14:26:05
+10:53:59
+04:52:51
+18:01:33
+11:10:29
+10:53:34
+03:35:48
+03:19:11
+23:13:24
+04:53:25
+22:08:34
+
+CREATE TABLE "sys"."t2" ("c0" TIME);
+COPY 5 RECORDS INTO "sys"."t2" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+07:23:20
+00:19:06
+12:50:37
+00:30:02
+21:01:23
+
+CREATE TABLE "sys"."t3" ("c0" TIME);
+COPY 8 RECORDS INTO "sys"."t3" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+16:58:19
+NULL
+21:19:34
+20:14:42
+16:39:56
+04:19:48
+00:19:06
+16:45:41
+
+CREATE TABLE "sys"."t4" ("c0" INTERVAL SECOND, CONSTRAINT "t4_c0_unique"
UNIQUE ("c0"));
+COPY 5 RECORDS INTO "sys"."t4" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+29578044.000
+60548068.000
+57514024.000
+2030212684.000
+1699639666.000
+
+select interval '-1680612084' second from t3 natural join (select t4.c0,
(cast(r'*' as boolean)) = false from t2, t0, t4) as sub0 group by t3.c0;
+ --error, overflow in conversion to time
+ROLLBACK;
diff --git a/sql/test/SQLancer/Tests/sqlancer04.stable.err
b/sql/test/SQLancer/Tests/sqlancer04.stable.err
--- a/sql/test/SQLancer/Tests/sqlancer04.stable.err
+++ b/sql/test/SQLancer/Tests/sqlancer04.stable.err
@@ -59,6 +59,10 @@ MAPI = (monetdb) /var/tmp/mtest-316864/
QUERY = select coalesce(-1129107763, '1415606329') from (values(1),(2)) as
t0(c0);
ERROR = !value too long for type (var)char(10)
CODE = 22001
+MAPI = (monetdb) /var/tmp/mtest-878466/.s.monetdb.33759
+QUERY = select interval '-1680612084' second from t3 natural join (select
t4.c0, (cast(r'*' as boolean)) = false from t2, t0, t4) as sub0 group by t3.c0;
+ERROR = !Overflow in convertion of second interval '29578044000' to time
+CODE = 22003
# 09:44:50 >
# 09:44:50 > "Done."
diff --git a/sql/test/SQLancer/Tests/sqlancer04.stable.out
b/sql/test/SQLancer/Tests/sqlancer04.stable.out
--- a/sql/test/SQLancer/Tests/sqlancer04.stable.out
+++ b/sql/test/SQLancer/Tests/sqlancer04.stable.out
@@ -371,6 +371,53 @@ stdout of test 'sqlancer04` in directory
% 24 # length
[ -7.015252551 ]
[ -7.015252551 ]
+#START TRANSACTION;
+#CREATE TABLE "sys"."t0" ("c0" TIME NOT NULL, CONSTRAINT "t0_c0_pkey" PRIMARY
KEY ("c0"));
+#COPY 15 RECORDS INTO "sys"."t0" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+#15:11:18
+#01:20:22
+#13:28:53
+#11:33:19
+#14:26:05
+#10:53:59
+#04:52:51
+#18:01:33
+#11:10:29
+#10:53:34
+#03:35:48
+#03:19:11
+#23:13:24
+#04:53:25
+#22:08:34
+[ 15 ]
+#CREATE TABLE "sys"."t2" ("c0" TIME);
+#COPY 5 RECORDS INTO "sys"."t2" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+#07:23:20
+#00:19:06
+#12:50:37
+#00:30:02
+#21:01:23
+[ 5 ]
+#CREATE TABLE "sys"."t3" ("c0" TIME);
+#COPY 8 RECORDS INTO "sys"."t3" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+#16:58:19
+#NULL
+#21:19:34
+#20:14:42
+#16:39:56
+#04:19:48
+#00:19:06
+#16:45:41
+[ 8 ]
+#CREATE TABLE "sys"."t4" ("c0" INTERVAL SECOND, CONSTRAINT "t4_c0_unique"
UNIQUE ("c0"));
+#COPY 5 RECORDS INTO "sys"."t4" FROM stdin USING DELIMITERS E'\t',E'\n','"';
+#29578044.000
+#60548068.000
+#57514024.000
+#2030212684.000
+#1699639666.000
+[ 5 ]
+#ROLLBACK;
# 09:44:50 >
# 09:44:50 > "Done."
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list