mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Fix timezone issues
This commit is contained in:
parent
a551e8d950
commit
e66e70870a
@ -28,15 +28,16 @@ public:
|
|||||||
|
|
||||||
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
|
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
|
||||||
{
|
{
|
||||||
this->checkArguments(arguments, /*is_result_type_date_or_date32*/ true);
|
this->checkArguments(arguments, /*is_result_type_date_or_date32*/ false);
|
||||||
|
|
||||||
const IDataType * from_type = arguments[0].type.get();
|
const IDataType * from_type = arguments[0].type.get();
|
||||||
WhichDataType which(from_type);
|
WhichDataType which(from_type);
|
||||||
|
|
||||||
|
std::string time_zone = extractTimeZoneNameFromFunctionArguments(arguments, 1, 0);
|
||||||
|
|
||||||
/// If the time zone is specified but empty, throw an exception.
|
/// If the time zone is specified but empty, throw an exception.
|
||||||
/// only validate the time_zone part if the number of arguments is 2.
|
/// only validate the time_zone part if the number of arguments is 2.
|
||||||
if ((which.isDateTime() || which.isDateTime64()) && arguments.size() == 2
|
if (arguments.size() == 2 && time_zone.empty())
|
||||||
&& extractTimeZoneNameFromFunctionArguments(arguments, 1, 0).empty())
|
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Function " + this->getName() + " supports a 2nd argument (optional) that must be non-empty and be a valid time zone",
|
"Function " + this->getName() + " supports a 2nd argument (optional) that must be non-empty and be a valid time zone",
|
||||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||||
@ -49,10 +50,10 @@ public:
|
|||||||
if (const auto * dt64 = checkAndGetDataType<DataTypeDateTime64>(arguments[0].type.get()))
|
if (const auto * dt64 = checkAndGetDataType<DataTypeDateTime64>(arguments[0].type.get()))
|
||||||
scale = dt64->getScale();
|
scale = dt64->getScale();
|
||||||
}
|
}
|
||||||
return std::make_shared<DataTypeDateTime64>(scale, extractTimeZoneNameFromFunctionArguments(arguments, 1, 0));
|
return std::make_shared<DataTypeDateTime64>(scale, time_zone);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return std::make_shared<DataTypeDateTime>();
|
return std::make_shared<DataTypeDateTime>(time_zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
|
||||||
|
@ -102,7 +102,7 @@ protected:
|
|||||||
"Function " + getName() + " supports 1 or 2 arguments. The optional 2nd argument must be "
|
"Function " + getName() + " supports 1 or 2 arguments. The optional 2nd argument must be "
|
||||||
"a constant string with a timezone name",
|
"a constant string with a timezone name",
|
||||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||||
if ((isDate(arguments[0].type) || isDate32(arguments[0].type)) && is_result_type_date_or_date32)
|
if (isDateOrDate32(arguments[0].type) && is_result_type_date_or_date32)
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"The timezone argument of function " + getName() + " is allowed only when the 1st argument has the type DateTime or DateTime64",
|
"The timezone argument of function " + getName() + " is allowed only when the 1st argument has the type DateTime or DateTime64",
|
||||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||||
|
Loading…
Reference in New Issue
Block a user