Merge pull request #72012 from ClickHouse/backport/24.10/71849

Backport #71849 to 24.10: Fix: add monotonic estimation for DateTime64 in toDayOfWeek
This commit is contained in:
robot-ch-test-poll2 2024-11-16 20:14:01 +04:00 committed by GitHub
commit 96b8005715
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 0 deletions

View File

@ -64,6 +64,7 @@ constexpr time_t MAX_DATETIME_DAY_NUM = 49710; // 2106-02-07
/// This factor transformation will say that the function is monotone everywhere.
struct ZeroTransform
{
static constexpr auto name = "Zero";
static UInt16 execute(Int64, const DateLUTImpl &) { return 0; }
static UInt16 execute(UInt32, const DateLUTImpl &) { return 0; }
static UInt16 execute(Int32, const DateLUTImpl &) { return 0; }

View File

@ -56,6 +56,21 @@ public:
: is_not_monotonic;
}
if (checkAndGetDataType<DataTypeDateTime64>(&type))
{
const auto & left_date_time = left.safeGet<DateTime64>();
TransformDateTime64<typename Transform::FactorTransform> transformer_left(left_date_time.getScale());
const auto & right_date_time = right.safeGet<DateTime64>();
TransformDateTime64<typename Transform::FactorTransform> transformer_right(right_date_time.getScale());
return transformer_left.execute(left_date_time.getValue(), date_lut)
== transformer_right.execute(right_date_time.getValue(), date_lut)
? is_monotonic
: is_not_monotonic;
}
return Transform::FactorTransform::execute(UInt32(left.safeGet<UInt64>()), date_lut)
== Transform::FactorTransform::execute(UInt32(right.safeGet<UInt64>()), date_lut)
? is_monotonic

View File

@ -0,0 +1,7 @@
DROP TABLE IF EXISTS decimal_dt;
CREATE TABLE decimal_dt (timestamp DateTime64(9)) ENGINE=MergeTree() ORDER BY timestamp;
INSERT INTO decimal_dt VALUES (toDate('2024-11-11')),(toDate('2024-11-12')),(toDate('2024-11-13')),(toDate('2024-11-14')),(toDate('2024-11-15')),(toDate('2024-11-16')),(toDate('2024-11-17'));
SELECT count() FROM decimal_dt WHERE toDayOfWeek(timestamp) > 3;
DROP TABLE IF EXISTS decimal_dt;