Fixed comparing Date and DateTime64

With a less flakky test
This commit is contained in:
Vasily Nemkov 2020-12-13 21:17:27 +03:00
parent 3261392f16
commit 5ff7baf663
5 changed files with 96 additions and 1 deletions

View File

@ -1216,7 +1216,10 @@ public:
{
return res;
}
else if (isColumnedAsDecimal(left_type) || isColumnedAsDecimal(right_type))
else if ((isColumnedAsDecimal(left_type) || isColumnedAsDecimal(right_type))
// Comparing Date and DateTime64 requires implicit conversion,
// otherwise Date is treated as number.
&& !(date_and_datetime && (isDate(left_type) || isDate(right_type))))
{
// compare
if (!allowDecimalComparison(left_type, right_type) && !date_and_datetime)

View File

@ -0,0 +1,3 @@
-1 DateTime64(1, \'UTC\') < 1 1 1 <= 1 1 1 = 0 0 0 >= 0 0 0 > 0 0 0 != 1 1 1
0 DateTime64(1, \'UTC\') < 0 0 0 <= 1 1 1 = 1 1 1 >= 1 1 1 > 0 0 0 != 0 0 0
1 DateTime64(1, \'UTC\') < 0 0 0 <= 0 0 0 = 0 0 0 >= 1 1 1 > 1 1 1 != 1 1 1

View File

@ -0,0 +1,43 @@
SELECT
n,
toTypeName(dt64) AS dt64_typename,
'<',
dt64 < dt,
toDateTime(dt64) < dt,
dt64 < toDateTime64(dt, 1, 'UTC'),
'<=',
dt64 <= dt,
toDateTime(dt64) <= dt,
dt64 <= toDateTime64(dt, 1, 'UTC'),
'=',
dt64 = dt,
toDateTime(dt64) = dt,
dt64 = toDateTime64(dt, 1, 'UTC'),
'>=',
dt64 >= dt,
toDateTime(dt64) >= dt,
dt64 >= toDateTime64(dt, 1, 'UTC'),
'>',
dt64 > dt,
toDateTime(dt64) > dt,
dt64 > toDateTime64(dt, 1, 'UTC'),
'!=',
dt64 != dt,
toDateTime(dt64) != dt,
dt64 != toDateTime64(dt, 1, 'UTC')
FROM
(
WITH toDateTime('2015-05-18 07:40:11') as value
SELECT
number - 1 as n,
toDateTime64(value, 1, 'UTC') AS dt64,
value - n as dt
FROM system.numbers
LIMIT 3
)

View File

@ -0,0 +1,3 @@
-1 DateTime64(1, \'UTC\') < 1 1 1 <= 1 1 1 = 0 0 0 >= 0 0 0 > 0 0 0 != 1 1 1
0 DateTime64(1, \'UTC\') < 0 0 0 <= 0 1 0 = 0 1 0 >= 1 1 1 > 1 0 1 != 1 0 1
1 DateTime64(1, \'UTC\') < 0 0 0 <= 0 0 0 = 0 0 0 >= 1 1 1 > 1 1 1 != 1 1 1

View File

@ -0,0 +1,43 @@
SELECT
n,
toTypeName(dt64) AS dt64_typename,
'<',
dt64 < d,
toDate(dt64) < d,
dt64 < toDateTime64(d, 1, 'UTC'),
'<=',
dt64 <= d,
toDate(dt64) <= d,
dt64 <= toDateTime64(d, 1, 'UTC'),
'=',
dt64 = d,
toDate(dt64) = d,
dt64 = toDateTime64(d, 1, 'UTC'),
'>=',
dt64 >= d,
toDate(dt64) >= d,
dt64 >= toDateTime64(d, 1, 'UTC'),
'>',
dt64 > d,
toDate(dt64) > d,
dt64 > toDateTime64(d, 1, 'UTC'),
'!=',
dt64 != d,
toDate(dt64) != d,
dt64 != toDateTime64(d, 1, 'UTC')
FROM
(
WITH toDateTime('2019-09-16 19:20:11') as val
SELECT
number - 1 as n,
toDateTime64(val, 1, 'UTC') AS dt64,
toDate(val, 'UTC') - n as d
FROM system.numbers
LIMIT 3
)