From 71d9d802750bf45d361f5da0b5a50e98bc3f5224 Mon Sep 17 00:00:00 2001 From: Vxider Date: Fri, 26 Nov 2021 18:03:41 +0000 Subject: [PATCH] timezone support for Tumble/Hop Start/End --- src/Functions/FunctionsWindow.cpp | 21 ++++++++++++------- ...049_window_view_window_functions.reference | 16 +++++++------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Functions/FunctionsWindow.cpp b/src/Functions/FunctionsWindow.cpp index 61513b18197..2f27ffb73b0 100644 --- a/src/Functions/FunctionsWindow.cpp +++ b/src/Functions/FunctionsWindow.cpp @@ -220,15 +220,19 @@ struct WindowImpl if (arguments.size() == 1) { auto type_ = WhichDataType(arguments[0].type); - if (!type_.isTuple() && !type_.isUInt32()) + if (type_.isTuple()) + return std::static_pointer_cast(arguments[0].type)->getElement(0); + else if (type_.isUInt32()) + return std::make_shared(); + else throw Exception( - "Illegal type of first argument of function " + function_name + " should be DateTime, Tuple or UInt32", ErrorCodes::ILLEGAL_COLUMN); + "Illegal type of first argument of function " + function_name + " should be DateTime, Tuple or UInt32", + ErrorCodes::ILLEGAL_COLUMN); } else { - WindowImpl::getReturnType(arguments, function_name); + return std::static_pointer_cast(WindowImpl::getReturnType(arguments, function_name))->getElement(0); } - return std::make_shared(); } [[maybe_unused]] static ColumnPtr dispatchForColumns(const ColumnsWithTypeAndName & arguments, const String & function_name) @@ -563,16 +567,19 @@ struct WindowImpl if (arguments.size() == 1) { auto type_ = WhichDataType(arguments[0].type); - if (!type_.isTuple() && !type_.isUInt32()) + if (type_.isTuple()) + return std::static_pointer_cast(arguments[0].type)->getElement(0); + else if (type_.isUInt32()) + return std::make_shared(); + else throw Exception( "Illegal type of first argument of function " + function_name + " should be DateTime, Tuple or UInt32", ErrorCodes::ILLEGAL_COLUMN); } else { - WindowImpl::getReturnType(arguments, function_name); + return std::static_pointer_cast(WindowImpl::getReturnType(arguments, function_name))->getElement(0); } - return std::make_shared(); } [[maybe_unused]] static ColumnPtr dispatchForColumns(const ColumnsWithTypeAndName & arguments, const String & function_name) diff --git a/tests/queries/0_stateless/01049_window_view_window_functions.reference b/tests/queries/0_stateless/01049_window_view_window_functions.reference index 3cb88966712..e8813db5a7d 100644 --- a/tests/queries/0_stateless/01049_window_view_window_functions.reference +++ b/tests/queries/0_stateless/01049_window_view_window_functions.reference @@ -18,21 +18,21 @@ SELECT TUMBLE(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' YEAR, SELECT TUMBLE(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, 'US/Samoa'); ('2020-01-09 00:00:00','2020-01-10 00:00:00') SELECT TUMBLE_START(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, 'US/Samoa'); -2020-01-09 14:00:00 +2020-01-09 00:00:00 SELECT toDateTime(TUMBLE_START(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, 'US/Samoa'), 'US/Samoa'); 2020-01-09 00:00:00 SELECT toDateTime(TUMBLE_START(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, 'US/Samoa'), 'US/Samoa'); 2020-01-09 00:00:00 SELECT TUMBLE_START(TUMBLE(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, 'US/Samoa')); -2020-01-09 14:00:00 +2020-01-09 00:00:00 SELECT TUMBLE_END(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, 'US/Samoa'); -2020-01-10 14:00:00 +2020-01-10 00:00:00 SELECT toDateTime(TUMBLE_END(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, 'US/Samoa'), 'US/Samoa'); 2020-01-10 00:00:00 SELECT toDateTime(TUMBLE_END(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, 'US/Samoa'), 'US/Samoa'); 2020-01-10 00:00:00 SELECT TUMBLE_END(TUMBLE(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, 'US/Samoa')); -2020-01-10 14:00:00 +2020-01-10 00:00:00 SELECT HOP(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL 1 SECOND, INTERVAL 3 SECOND, 'US/Samoa'); ('2020-01-09 11:59:59','2020-01-09 12:00:02') SELECT HOP(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL 1 MINUTE, INTERVAL 3 MINUTE, 'US/Samoa'); @@ -52,18 +52,18 @@ SELECT HOP(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL 1 YEAR, INTER SELECT HOP(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, INTERVAL '3' DAY, 'US/Samoa'); ('2020-01-07 00:00:00','2020-01-10 00:00:00') SELECT HOP_START(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, INTERVAL '3' DAY, 'US/Samoa'); -2020-01-07 14:00:00 +2020-01-07 00:00:00 SELECT toDateTime(HOP_START(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, INTERVAL '3' DAY, 'US/Samoa'), 'US/Samoa'); 2020-01-07 00:00:00 SELECT toDateTime(HOP_START(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, INTERVAL '3' DAY, 'US/Samoa'), 'US/Samoa'); 2020-01-07 00:00:00 SELECT HOP_START(HOP(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, INTERVAL '3' DAY, 'US/Samoa')); -2020-01-07 14:00:00 +2020-01-07 00:00:00 SELECT HOP_END(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, INTERVAL '3' DAY, 'US/Samoa'); -2020-01-10 14:00:00 +2020-01-10 00:00:00 SELECT toDateTime(HOP_END(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, INTERVAL '3' DAY, 'US/Samoa'), 'US/Samoa'); 2020-01-10 00:00:00 SELECT toDateTime(HOP_END(toDateTime('2020-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, INTERVAL '3' DAY, 'US/Samoa'), 'US/Samoa'); 2020-01-10 00:00:00 SELECT HOP_END(HOP(toDateTime('2019-01-09 12:00:01', 'US/Samoa'), INTERVAL '1' DAY, INTERVAL '3' DAY, 'US/Samoa')); -2019-01-10 14:00:00 +2019-01-10 00:00:00