diff --git a/src/DataTypes/DataTypeDateTime.h b/src/DataTypes/DataTypeDateTime.h index 84df8b21813..926d529a5d8 100644 --- a/src/DataTypes/DataTypeDateTime.h +++ b/src/DataTypes/DataTypeDateTime.h @@ -19,9 +19,12 @@ public: TimezoneMixin(const TimezoneMixin &) = default; const DateLUTImpl & getTimeZone() const { return time_zone; } + bool hasExplicitTimeZone() const { return has_explicit_time_zone; } protected: + /// true if time zone name was provided in data type parameters, false if it's using default time zone. bool has_explicit_time_zone; + const DateLUTImpl & time_zone; const DateLUTImpl & utc_time_zone; }; diff --git a/src/Functions/FunctionCustomWeekToSomething.h b/src/Functions/FunctionCustomWeekToSomething.h index 4050bb512bd..c6f56fdc50a 100644 --- a/src/Functions/FunctionCustomWeekToSomething.h +++ b/src/Functions/FunctionCustomWeekToSomething.h @@ -5,7 +5,6 @@ #include #include #include -#include #include diff --git a/src/Functions/extractTimeZoneFromFunctionArguments.cpp b/src/Functions/extractTimeZoneFromFunctionArguments.cpp index 0ba08b3c612..dbc014ad2eb 100644 --- a/src/Functions/extractTimeZoneFromFunctionArguments.cpp +++ b/src/Functions/extractTimeZoneFromFunctionArguments.cpp @@ -44,9 +44,9 @@ std::string extractTimeZoneNameFromFunctionArguments(const ColumnsWithTypeAndNam /// If time zone is attached to an argument of type DateTime. if (const auto * type = checkAndGetDataType(arguments[datetime_arg_num].type.get())) - return type->getTimeZone().getTimeZone(); + return type->hasExplicitTimeZone() ? type->getTimeZone().getTimeZone() : std::string(); if (const auto * type = checkAndGetDataType(arguments[datetime_arg_num].type.get())) - return type->getTimeZone().getTimeZone(); + return type->hasExplicitTimeZone() ? type->getTimeZone().getTimeZone() : std::string(); return {}; } diff --git a/src/Functions/extractTimeZoneFromFunctionArguments.h b/src/Functions/extractTimeZoneFromFunctionArguments.h index 6323b45f568..9dd3fdd4903 100644 --- a/src/Functions/extractTimeZoneFromFunctionArguments.h +++ b/src/Functions/extractTimeZoneFromFunctionArguments.h @@ -13,6 +13,7 @@ namespace DB class Block; /// Determine working timezone either from optional argument with time zone name or from time zone in DateTime type of argument. +/// Returns empty string if default time zone should be used. std::string extractTimeZoneNameFromFunctionArguments( const ColumnsWithTypeAndName & arguments, size_t time_zone_arg_num, size_t datetime_arg_num); diff --git a/tests/queries/0_stateless/01836_date_time_keep_default_timezone_on_operations_den_crane.reference b/tests/queries/0_stateless/01836_date_time_keep_default_timezone_on_operations_den_crane.reference new file mode 100644 index 00000000000..fc624e3510f --- /dev/null +++ b/tests/queries/0_stateless/01836_date_time_keep_default_timezone_on_operations_den_crane.reference @@ -0,0 +1,6 @@ +DateTime +DateTime +DateTime(\'UTC\') +DateTime64(3) +DateTime64(3) +DateTime64(3, \'UTC\') diff --git a/tests/queries/0_stateless/01836_date_time_keep_default_timezone_on_operations_den_crane.sql b/tests/queries/0_stateless/01836_date_time_keep_default_timezone_on_operations_den_crane.sql new file mode 100644 index 00000000000..be47cfb0411 --- /dev/null +++ b/tests/queries/0_stateless/01836_date_time_keep_default_timezone_on_operations_den_crane.sql @@ -0,0 +1,26 @@ +SELECT toTypeName(now()); +SELECT toTypeName(now() - 1); +SELECT toTypeName(now('UTC') - 1); + +SELECT toTypeName(now64(3)); +SELECT toTypeName(now64(3) - 1); +SELECT toTypeName(toTimeZone(now64(3), 'UTC') - 1); + +DROP TABLE IF EXISTS tt_null; +DROP TABLE IF EXISTS tt; +DROP TABLE IF EXISTS tt_mv; + +create table tt_null(p String) engine = Null; + +create table tt(p String,tmin AggregateFunction(min, DateTime)) +engine = AggregatingMergeTree order by p; + +create materialized view tt_mv to tt as +select p, minState(now() - interval 30 minute) as tmin +from tt_null group by p; + +insert into tt_null values('x'); + +DROP TABLE tt_null; +DROP TABLE tt; +DROP TABLE tt_mv;