This commit is contained in:
Alexey Milovidov 2024-03-15 11:32:21 +01:00
parent 4eda78440d
commit 4290b1fe2c
2 changed files with 13 additions and 38 deletions

View File

@ -1980,13 +1980,6 @@ public:
static constexpr bool to_datetime64 = std::is_same_v<ToDataType, DataTypeDateTime64>; static constexpr bool to_datetime64 = std::is_same_v<ToDataType, DataTypeDateTime64>;
static constexpr bool to_string_or_fixed_string = std::is_same_v<ToDataType, DataTypeFixedString> ||
std::is_same_v<ToDataType, DataTypeString>;
static constexpr bool to_date_or_datetime = std::is_same_v<ToDataType, DataTypeDate> ||
std::is_same_v<ToDataType, DataTypeDate32> ||
std::is_same_v<ToDataType, DataTypeDateTime>;
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionConvert>(context); } static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionConvert>(context); }
static FunctionPtr create() { return std::make_shared<FunctionConvert>(); } static FunctionPtr create() { return std::make_shared<FunctionConvert>(); }
@ -2003,8 +1996,7 @@ public:
bool isInjective(const ColumnsWithTypeAndName &) const override { return std::is_same_v<Name, NameToString>; } bool isInjective(const ColumnsWithTypeAndName &) const override { return std::is_same_v<Name, NameToString>; }
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & arguments) const override bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & arguments) const override
{ {
/// TODO: We can make more optimizations here. return !(IsDataTypeDateOrDateTime<ToDataType> && isNumber(*arguments[0].type));
return !(to_date_or_datetime && isNumber(*arguments[0].type));
} }
using DefaultReturnTypeGetter = std::function<DataTypePtr(const ColumnsWithTypeAndName &)>; using DefaultReturnTypeGetter = std::function<DataTypePtr(const ColumnsWithTypeAndName &)>;
@ -2327,7 +2319,7 @@ private:
} }
bool done = false; bool done = false;
if constexpr (to_string_or_fixed_string) if constexpr (std::is_same_v<ToDataType, DataTypeFixedString> || std::is_same_v<ToDataType, DataTypeString>)
{ {
done = callOnIndexAndDataType<ToDataType>(from_type->getTypeId(), call, ConvertDefaultBehaviorTag{}); done = callOnIndexAndDataType<ToDataType>(from_type->getTypeId(), call, ConvertDefaultBehaviorTag{});
} }
@ -3155,7 +3147,6 @@ public:
} }
private: private:
const char * cast_name; const char * cast_name;
MonotonicityForRange monotonicity_for_range; MonotonicityForRange monotonicity_for_range;
@ -4623,26 +4614,12 @@ arguments, result_type, input_rows_count); \
using Types = std::decay_t<decltype(types)>; using Types = std::decay_t<decltype(types)>;
using ToDataType = typename Types::LeftType; using ToDataType = typename Types::LeftType;
if constexpr ( if constexpr (is_any_of<ToDataType,
std::is_same_v<ToDataType, DataTypeUInt16> || DataTypeUInt16, DataTypeUInt32, DataTypeUInt64, DataTypeUInt128, DataTypeUInt256,
std::is_same_v<ToDataType, DataTypeUInt32> || DataTypeInt8, DataTypeInt16, DataTypeInt32, DataTypeInt64, DataTypeInt128, DataTypeInt256,
std::is_same_v<ToDataType, DataTypeUInt64> || DataTypeFloat32, DataTypeFloat64,
std::is_same_v<ToDataType, DataTypeUInt128> || DataTypeDate, DataTypeDate32, DataTypeDateTime,
std::is_same_v<ToDataType, DataTypeUInt256> || DataTypeUUID, DataTypeIPv4, DataTypeIPv6>)
std::is_same_v<ToDataType, DataTypeInt8> ||
std::is_same_v<ToDataType, DataTypeInt16> ||
std::is_same_v<ToDataType, DataTypeInt32> ||
std::is_same_v<ToDataType, DataTypeInt64> ||
std::is_same_v<ToDataType, DataTypeInt128> ||
std::is_same_v<ToDataType, DataTypeInt256> ||
std::is_same_v<ToDataType, DataTypeFloat32> ||
std::is_same_v<ToDataType, DataTypeFloat64> ||
std::is_same_v<ToDataType, DataTypeDate> ||
std::is_same_v<ToDataType, DataTypeDate32> ||
std::is_same_v<ToDataType, DataTypeDateTime> ||
std::is_same_v<ToDataType, DataTypeUUID> ||
std::is_same_v<ToDataType, DataTypeIPv4> ||
std::is_same_v<ToDataType, DataTypeIPv6>)
{ {
ret = createWrapper(from_type, checkAndGetDataType<ToDataType>(to_type.get()), requested_result_is_nullable); ret = createWrapper(from_type, checkAndGetDataType<ToDataType>(to_type.get()), requested_result_is_nullable);
return true; return true;
@ -4662,12 +4639,10 @@ arguments, result_type, input_rows_count); \
ret = createEnumWrapper(from_type, checkAndGetDataType<ToDataType>(to_type.get())); ret = createEnumWrapper(from_type, checkAndGetDataType<ToDataType>(to_type.get()));
return true; return true;
} }
if constexpr ( if constexpr (is_any_of<ToDataType,
std::is_same_v<ToDataType, DataTypeDecimal<Decimal32>> || DataTypeDecimal<Decimal32>, DataTypeDecimal<Decimal64>,
std::is_same_v<ToDataType, DataTypeDecimal<Decimal64>> || DataTypeDecimal<Decimal128>, DataTypeDecimal<Decimal256>,
std::is_same_v<ToDataType, DataTypeDecimal<Decimal128>> || DataTypeDateTime64>)
std::is_same_v<ToDataType, DataTypeDecimal<Decimal256>> ||
std::is_same_v<ToDataType, DataTypeDateTime64>)
{ {
ret = createDecimalWrapper(from_type, checkAndGetDataType<ToDataType>(to_type.get()), requested_result_is_nullable); ret = createDecimalWrapper(from_type, checkAndGetDataType<ToDataType>(to_type.get()), requested_result_is_nullable);
return true; return true;

View File

@ -303,7 +303,7 @@ private:
}; };
ColumnsWithTypeAndName arguments_with_cast_type; ColumnsWithTypeAndName arguments_with_cast_type;
arguments_with_cast_type.reserve(arguments.size()); arguments_with_cast_type.reserve(arguments.size() + 1);
arguments_with_cast_type.emplace_back(arguments[0]); arguments_with_cast_type.emplace_back(arguments[0]);
arguments_with_cast_type.emplace_back(second_argument); arguments_with_cast_type.emplace_back(second_argument);