Changeset: 41d10861c113 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=41d10861c113
Modified Files:
sql/backends/monet5/sql.c
sql/backends/monet5/sql_round_impl.h
sql/test/miscellaneous/Tests/simple_selects.sql
sql/test/miscellaneous/Tests/simple_selects.stable.out
Branch: Jun2020
Log Message:
Handle NULL values on string to interval conversion
diffs (88 lines):
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
@@ -3808,18 +3808,26 @@ month_interval_str(int *ret, const str *
{
lng res;
- if (interval_from_str(*s, *d, *sk, &res) < 0)
- throw(SQL, "calc.month_interval", SQLSTATE(42000) "Wrong format
(%s)", *s);
- assert((lng) GDK_int_min <= res && res <= (lng) GDK_int_max);
- *ret = (int) res;
+ if (strNil(*s)) {
+ *ret = int_nil;
+ } else {
+ if (interval_from_str(*s, *d, *sk, &res) < 0)
+ throw(SQL, "calc.month_interval", SQLSTATE(42000)
"Wrong format (%s)", *s);
+ assert((lng) GDK_int_min <= res && res <= (lng) GDK_int_max);
+ *ret = (int) res;
+ }
return MAL_SUCCEED;
}
str
second_interval_str(lng *res, const str *s, const int *d, const int *sk)
{
- if (interval_from_str(*s, *d, *sk, res) < 0)
- throw(SQL, "calc.second_interval", SQLSTATE(42000) "Wrong
format (%s)", *s);
+ if (strNil(*s)) {
+ *res = lng_nil;
+ } else {
+ if (interval_from_str(*s, *d, *sk, res) < 0)
+ throw(SQL, "calc.second_interval", SQLSTATE(42000)
"Wrong format (%s)", *s);
+ }
return MAL_SUCCEED;
}
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
@@ -452,7 +452,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) {
diff --git a/sql/test/miscellaneous/Tests/simple_selects.sql
b/sql/test/miscellaneous/Tests/simple_selects.sql
--- a/sql/test/miscellaneous/Tests/simple_selects.sql
+++ b/sql/test/miscellaneous/Tests/simple_selects.sql
@@ -160,3 +160,6 @@ select greatest(null, null);
select sql_min(null, null);
select 'a' like 'a' escape 'a'; --error, like sequence ending with escape
character
+
+select cast(x as interval second) from (values ('1'), (NULL), ('100'), (NULL))
as x(x);
+select cast(x as interval month) from (values ('1'), (NULL), ('100'), (NULL))
as x(x);
diff --git a/sql/test/miscellaneous/Tests/simple_selects.stable.out
b/sql/test/miscellaneous/Tests/simple_selects.stable.out
--- a/sql/test/miscellaneous/Tests/simple_selects.stable.out
+++ b/sql/test/miscellaneous/Tests/simple_selects.stable.out
@@ -387,6 +387,24 @@ stdout of test 'simple_selects` in direc
% char # type
% 0 # length
[ NULL ]
+#select cast(x as interval second) from (values ('1'), (NULL), ('100'),
(NULL)) as x(x);
+% .%6 # table_name
+% %6 # name
+% sec_interval # type
+% 7 # length
+[ 1.000 ]
+[ NULL ]
+[ 100.000 ]
+[ NULL ]
+#select cast(x as interval month) from (values ('1'), (NULL), ('100'), (NULL))
as x(x);
+% .%6 # table_name
+% %6 # name
+% month_interval # type
+% 3 # length
+[ 1 ]
+[ NULL ]
+[ 100 ]
+[ NULL ]
# 17:31:38 >
# 17:31:38 > "Done."
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list