mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Merge pull request #23392 from ClickHouse/fix-4854
Keep default timezone on DateTime operations if it was not provided explicitly #4854
This commit is contained in:
commit
20a5fed53e
@ -19,9 +19,12 @@ public:
|
|||||||
TimezoneMixin(const TimezoneMixin &) = default;
|
TimezoneMixin(const TimezoneMixin &) = default;
|
||||||
|
|
||||||
const DateLUTImpl & getTimeZone() const { return time_zone; }
|
const DateLUTImpl & getTimeZone() const { return time_zone; }
|
||||||
|
bool hasExplicitTimeZone() const { return has_explicit_time_zone; }
|
||||||
|
|
||||||
protected:
|
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;
|
bool has_explicit_time_zone;
|
||||||
|
|
||||||
const DateLUTImpl & time_zone;
|
const DateLUTImpl & time_zone;
|
||||||
const DateLUTImpl & utc_time_zone;
|
const DateLUTImpl & utc_time_zone;
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include <Functions/CustomWeekTransforms.h>
|
#include <Functions/CustomWeekTransforms.h>
|
||||||
#include <Functions/IFunctionImpl.h>
|
#include <Functions/IFunctionImpl.h>
|
||||||
#include <Functions/TransformDateTime64.h>
|
#include <Functions/TransformDateTime64.h>
|
||||||
#include <Functions/extractTimeZoneFromFunctionArguments.h>
|
|
||||||
#include <IO/WriteHelpers.h>
|
#include <IO/WriteHelpers.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ std::string extractTimeZoneNameFromFunctionArguments(const ColumnsWithTypeAndNam
|
|||||||
|
|
||||||
/// If time zone is attached to an argument of type DateTime.
|
/// If time zone is attached to an argument of type DateTime.
|
||||||
if (const auto * type = checkAndGetDataType<DataTypeDateTime>(arguments[datetime_arg_num].type.get()))
|
if (const auto * type = checkAndGetDataType<DataTypeDateTime>(arguments[datetime_arg_num].type.get()))
|
||||||
return type->getTimeZone().getTimeZone();
|
return type->hasExplicitTimeZone() ? type->getTimeZone().getTimeZone() : std::string();
|
||||||
if (const auto * type = checkAndGetDataType<DataTypeDateTime64>(arguments[datetime_arg_num].type.get()))
|
if (const auto * type = checkAndGetDataType<DataTypeDateTime64>(arguments[datetime_arg_num].type.get()))
|
||||||
return type->getTimeZone().getTimeZone();
|
return type->hasExplicitTimeZone() ? type->getTimeZone().getTimeZone() : std::string();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ namespace DB
|
|||||||
class Block;
|
class Block;
|
||||||
|
|
||||||
/// Determine working timezone either from optional argument with time zone name or from time zone in DateTime type of argument.
|
/// 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(
|
std::string extractTimeZoneNameFromFunctionArguments(
|
||||||
const ColumnsWithTypeAndName & arguments, size_t time_zone_arg_num, size_t datetime_arg_num);
|
const ColumnsWithTypeAndName & arguments, size_t time_zone_arg_num, size_t datetime_arg_num);
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
DateTime
|
||||||
|
DateTime
|
||||||
|
DateTime(\'UTC\')
|
||||||
|
DateTime64(3)
|
||||||
|
DateTime64(3)
|
||||||
|
DateTime64(3, \'UTC\')
|
@ -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;
|
Loading…
Reference in New Issue
Block a user