mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
Merge pull request #45914 from jh0x/improve-into-date-from-uint16
Improve behaviour of conversion into Date for boundary value 65535
This commit is contained in:
commit
0ba246ca53
@ -377,7 +377,7 @@ struct ToDateTransform32Or64
|
|||||||
static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl & time_zone)
|
static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl & time_zone)
|
||||||
{
|
{
|
||||||
// since converting to Date, no need in values outside of default LUT range.
|
// since converting to Date, no need in values outside of default LUT range.
|
||||||
return (from < DATE_LUT_MAX_DAY_NUM)
|
return (from <= DATE_LUT_MAX_DAY_NUM)
|
||||||
? from
|
? from
|
||||||
: time_zone.toDayNum(std::min(time_t(from), time_t(0xFFFFFFFF)));
|
: time_zone.toDayNum(std::min(time_t(from), time_t(0xFFFFFFFF)));
|
||||||
}
|
}
|
||||||
@ -394,7 +394,7 @@ struct ToDateTransform32Or64Signed
|
|||||||
/// The function should be monotonic (better for query optimizations), so we saturate instead of overflow.
|
/// The function should be monotonic (better for query optimizations), so we saturate instead of overflow.
|
||||||
if (from < 0)
|
if (from < 0)
|
||||||
return 0;
|
return 0;
|
||||||
return (from < DATE_LUT_MAX_DAY_NUM)
|
return (from <= DATE_LUT_MAX_DAY_NUM)
|
||||||
? static_cast<ToType>(from)
|
? static_cast<ToType>(from)
|
||||||
: time_zone.toDayNum(std::min(time_t(from), time_t(0xFFFFFFFF)));
|
: time_zone.toDayNum(std::min(time_t(from), time_t(0xFFFFFFFF)));
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
2149-06-06 65535
|
||||||
|
2149-06-06 toUInt16(65535)
|
||||||
|
2149-06-06 toInt32(65535)
|
||||||
|
2149-06-06 toUInt32(65535)
|
||||||
|
2149-06-06 toDate(65535)
|
||||||
|
2149-06-06 CAST(65535 as UInt16)
|
||||||
|
2149-06-06 CAST(65535 as Int32)
|
||||||
|
2149-06-06 CAST(65535 as UInt32)
|
||||||
|
2149-06-06 CAST(65535 as Date)
|
||||||
|
2149-06-05 65534
|
||||||
|
2149-06-05 toUInt16(65534)
|
||||||
|
2149-06-05 toInt32(65534)
|
||||||
|
2149-06-05 toUInt32(65534)
|
||||||
|
2149-06-05 toDate(65534)
|
||||||
|
2149-06-05 CAST(65534 as UInt16)
|
||||||
|
2149-06-05 CAST(65534 as Int32)
|
||||||
|
2149-06-05 CAST(65534 as UInt32)
|
||||||
|
2149-06-05 CAST(65534 as Date)
|
||||||
|
1970-01-01 65536
|
||||||
|
1970-01-01 toUInt16(65536)
|
||||||
|
1970-01-01 toInt32(65536)
|
||||||
|
1970-01-01 toUInt32(65536)
|
||||||
|
1970-01-01 toDate(65536)
|
||||||
|
1970-01-01 CAST(65536 as UInt16)
|
||||||
|
1970-01-01 CAST(65536 as Int32)
|
||||||
|
1970-01-01 CAST(65536 as UInt32)
|
||||||
|
1970-01-01 CAST(65536 as Date)
|
@ -0,0 +1,72 @@
|
|||||||
|
DROP TABLE IF EXISTS 02540_date;
|
||||||
|
CREATE TABLE 02540_date (txt String, x Date) engine=Memory;
|
||||||
|
|
||||||
|
-- Date: Supported range of values: [1970-01-01, 2149-06-06].
|
||||||
|
-- ^----closed interval---^
|
||||||
|
|
||||||
|
INSERT INTO 02540_date VALUES('65535', 65535);
|
||||||
|
INSERT INTO 02540_date VALUES('toUInt16(65535)', toUInt16(65535)); -- #43370 weird one -> used to be 1970-01-01
|
||||||
|
INSERT INTO 02540_date VALUES('toInt32(65535)', toInt32(65535));
|
||||||
|
INSERT INTO 02540_date VALUES('toUInt32(65535)', toUInt32(65535));
|
||||||
|
INSERT INTO 02540_date VALUES('toDate(65535)', toDate(65535));
|
||||||
|
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65535 as UInt16)', CAST(65535 as UInt16));
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65535 as Int32)', CAST(65535 as Int32));
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65535 as UInt32)', CAST(65535 as UInt32));
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65535 as Date)', CAST(65535 as Date));
|
||||||
|
|
||||||
|
INSERT INTO 02540_date VALUES('65534', 65534);
|
||||||
|
INSERT INTO 02540_date VALUES('toUInt16(65534)', toUInt16(65534));
|
||||||
|
INSERT INTO 02540_date VALUES('toInt32(65534)', toInt32(65534));
|
||||||
|
INSERT INTO 02540_date VALUES('toUInt32(65534)', toUInt32(65534));
|
||||||
|
INSERT INTO 02540_date VALUES('toDate(65534)', toDate(65534));
|
||||||
|
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65534 as UInt16)', CAST(65534 as UInt16));
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65534 as Int32)', CAST(65534 as Int32));
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65534 as UInt32)', CAST(65534 as UInt32));
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65534 as Date)', CAST(65534 as Date));
|
||||||
|
|
||||||
|
INSERT INTO 02540_date VALUES('65536', 65536);
|
||||||
|
INSERT INTO 02540_date VALUES('toUInt16(65536)', toUInt16(65536));
|
||||||
|
INSERT INTO 02540_date VALUES('toInt32(65536)', toInt32(65536));
|
||||||
|
INSERT INTO 02540_date VALUES('toUInt32(65536)', toUInt32(65536));
|
||||||
|
INSERT INTO 02540_date VALUES('toDate(65536)', toDate(65536));
|
||||||
|
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65536 as UInt16)', CAST(65536 as UInt16));
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65536 as Int32)', CAST(65536 as Int32));
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65536 as UInt32)', CAST(65536 as UInt32));
|
||||||
|
INSERT INTO 02540_date VALUES('CAST(65536 as Date)', CAST(65536 as Date));
|
||||||
|
|
||||||
|
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == '65535';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toUInt16(65535)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toInt32(65535)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toUInt32(65535)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toDate(65535)';
|
||||||
|
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65535 as UInt16)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65535 as Int32)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65535 as UInt32)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65535 as Date)';
|
||||||
|
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == '65534';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toUInt16(65534)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toInt32(65534)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toUInt32(65534)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toDate(65534)';
|
||||||
|
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65534 as UInt16)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65534 as Int32)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65534 as UInt32)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65534 as Date)';
|
||||||
|
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == '65536';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toUInt16(65536)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toInt32(65536)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toUInt32(65536)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'toDate(65536)';
|
||||||
|
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65536 as UInt16)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65536 as Int32)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65536 as UInt32)';
|
||||||
|
SELECT x, txt FROM 02540_date WHERE txt == 'CAST(65536 as Date)';
|
Loading…
Reference in New Issue
Block a user