From 96809d0c77b2f8d044ad53d4e4d87b8c079a17ac Mon Sep 17 00:00:00 2001 From: Vasily Nemkov Date: Sun, 10 Nov 2019 16:23:02 +0300 Subject: [PATCH] Fixed test to not fail under UB-sanitizer + extra negative test case for toDateTime64 --- .../queries/0_stateless/00921_datetime64_basic.sql | 11 ++--------- .../00921_datetime64_compatibility.python | 6 ++++-- .../00921_datetime64_compatibility.reference | 14 -------------- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/dbms/tests/queries/0_stateless/00921_datetime64_basic.sql b/dbms/tests/queries/0_stateless/00921_datetime64_basic.sql index acd3e5145bc..4b4360ae960 100644 --- a/dbms/tests/queries/0_stateless/00921_datetime64_basic.sql +++ b/dbms/tests/queries/0_stateless/00921_datetime64_basic.sql @@ -7,9 +7,7 @@ SELECT CAST(1 as DateTime64(100)); -- { serverError 69 } # too big scale SELECT CAST(1 as DateTime64(-1)); -- { serverError 43 } # signed scale parameter type SELECT CAST(1 as DateTime64(3, 'qqq')); -- { serverError 1000 } # invalid timezone SELECT toDateTime64('2019-09-16 19:20:11.234', 3, 'qqq'); -- { serverError 1000 } # invalid timezone -SELECT toDateTime64('2019-09-16 19:20', 3, 'qqq'); -- { serverError 1000 } # invalid timezone - --- SELECT toDateTime64('2019-09-16 19:20:11', 3), ignore(now64(3)); +SELECT toDateTime64('2019-09-16 19:20', 3, 'UTC'); -- { serverError 41 } # Cannot parse DateTime64(3, 'UTC') from String. CREATE TABLE A(t DateTime64(3, 'UTC')) ENGINE = MergeTree() ORDER BY t; INSERT INTO A(t) VALUES ('2019-05-03 11:25:25.123456789'); @@ -18,9 +16,4 @@ SELECT toString(t, 'UTC'), toDate(t), toStartOfDay(t), toStartOfQuarter(t), toTi SELECT toDateTime64('2019-09-16 19:20:11.234', 3, 'Europe/Minsk'); - - -DROP TABLE A; - -- issue toDate does a reinterpret_cast of the datetime64 which is incorrect --- for the example above, it returns 2036-08-23 which is 0x5F15 days after epoch --- the datetime64 is 0x159B2550CB345F15 \ No newline at end of file +DROP TABLE A; \ No newline at end of file diff --git a/dbms/tests/queries/0_stateless/00921_datetime64_compatibility.python b/dbms/tests/queries/0_stateless/00921_datetime64_compatibility.python index f38b86d4cc4..27b9f8dc820 100755 --- a/dbms/tests/queries/0_stateless/00921_datetime64_compatibility.python +++ b/dbms/tests/queries/0_stateless/00921_datetime64_compatibility.python @@ -75,8 +75,10 @@ CAST(N as DateTime64(0)) CAST(N as DateTime64(3)) CAST(N as DateTime64(6)) CAST(N as DateTime64(9)) -CAST(N as DateTime64(12)) -CAST(N as DateTime64(18)) +# Casting our test values to DateTime(12) will cause an overflow and hence will fail the test under UB sanitizer. +# CAST(N as DateTime64(12)) +# DateTime64(18) will always fail due to zero precision, but it is Ok to test here: +# CAST(N as DateTime64(18)) formatDateTime(N, '%C %d %D %e %F %H %I %j %m %M %p %R %S %T %u %V %w %y %Y %%') """.splitlines() diff --git a/dbms/tests/queries/0_stateless/00921_datetime64_compatibility.reference b/dbms/tests/queries/0_stateless/00921_datetime64_compatibility.reference index 3a408fb27bc..120dbee6434 100644 --- a/dbms/tests/queries/0_stateless/00921_datetime64_compatibility.reference +++ b/dbms/tests/queries/0_stateless/00921_datetime64_compatibility.reference @@ -345,20 +345,6 @@ SELECT CAST(N as DateTime64(9)) "DateTime64(9)","2019-09-16 19:20:11.000000000" "DateTime64(9)","2019-09-16 19:20:11.234000000" ------------------------------------------ -SELECT CAST(N as DateTime64(12)) -"DateTime64(12)","1970-01-08 03:52:33.734688112640" -"DateTime64(12)","1970-01-08 23:12:44.734688112640" - -Code: 407: DateTime64 convert overflow. ------------------------------------------- -SELECT CAST(N as DateTime64(18)) - -Code: 69: Precision 0 is out of bounds. - -Code: 69: Precision 0 is out of bounds. - -Code: 69: Precision 0 is out of bounds. ------------------------------------------- SELECT formatDateTime(N, \'%C %d %D %e %F %H %I %j %m %M %p %R %S %T %u %V %w %y %Y %%\') "String","20 16 09/16/19 16 2019-09-16 00 12 259 09 00 AM 00:00 00 00:00:00 1 38 1 19 2019 %" "String","20 16 09/16/19 16 2019-09-16 19 07 259 09 20 PM 19:20 11 19:20:11 1 38 1 19 2019 %"