Fixed binary operators with DateTime, now result is of same TimeZone as the DateTime operand

This commit is contained in:
Vasily Nemkov 2020-03-10 14:15:14 +08:00
parent 1acffc674d
commit 308b7bfe54

View File

@ -823,6 +823,18 @@ public:
type_res = std::make_shared<LeftDataType>(left.getPrecision(), left.getScale());
else if constexpr (IsDataTypeDecimal<RightDataType>)
type_res = std::make_shared<RightDataType>(right.getPrecision(), right.getScale());
// Special case for DateTime: binary OPS should not looze the timezone of the result type,
// but reuse timezone of DateTime argument.
// NOTE: binary plus/minus are not allowed on DateTime64, and we are not handling it here.
else if constexpr (std::is_same_v<ResultDataType, DataTypeDateTime>)
{
const TimezoneMixin * tz = nullptr;
if constexpr (std::is_same_v<RightDataType, DataTypeDateTime>)
tz = &right;
if constexpr (std::is_same_v<LeftDataType, DataTypeDateTime>)
tz = &left;
type_res = std::make_shared<ResultDataType>(*tz);
}
else
type_res = std::make_shared<ResultDataType>();
return true;