[fix](datetime) Added datetime compatibility logic (#25791)

This commit is contained in:
zclllyybb
2023-10-24 10:37:57 +08:00
committed by GitHub
parent f23fdcbbef
commit f9f539221f
2 changed files with 17 additions and 6 deletions

View File

@ -75,11 +75,11 @@ struct StrToDate {
}
static DataTypePtr get_return_type_impl(const DataTypes& arguments) {
if constexpr (IsDateType<DateType> || IsDateV2Type<DateType>) {
return make_nullable(std::make_shared<DataTypeDateV2>());
if constexpr (IsDataTypeDateTimeV2<DateType>) {
// max scale
return make_nullable(std::make_shared<DataTypeDateTimeV2>(6));
}
//datetimev2
return make_nullable(std::make_shared<DataTypeDateTimeV2>(6));
return make_nullable(std::make_shared<DateType>());
}
static StringRef rewrite_specific_format(const char* raw_str, size_t str_size) {
@ -1272,8 +1272,10 @@ public:
}
};
using FunctionStrToDate = FunctionOtherTypesToDateType<StrToDate<DataTypeDateV2>>;
using FunctionStrToDatetime = FunctionOtherTypesToDateType<StrToDate<DataTypeDateTimeV2>>;
using FunctionStrToDate = FunctionOtherTypesToDateType<StrToDate<DataTypeDate>>;
using FunctionStrToDatetime = FunctionOtherTypesToDateType<StrToDate<DataTypeDateTime>>;
using FunctionStrToDateV2 = FunctionOtherTypesToDateType<StrToDate<DataTypeDateV2>>;
using FunctionStrToDatetimeV2 = FunctionOtherTypesToDateType<StrToDate<DataTypeDateTimeV2>>;
using FunctionMakeDate = FunctionOtherTypesToDateType<MakeDateImpl>;
using FunctionDateTruncDate = FunctionOtherTypesToDateType<DateTrunc<DataTypeDate>>;
using FunctionDateTruncDateV2 = FunctionOtherTypesToDateType<DateTrunc<DataTypeDateV2>>;
@ -1283,6 +1285,8 @@ using FunctionDateTruncDatetimeV2 = FunctionOtherTypesToDateType<DateTrunc<DataT
void register_function_timestamp(SimpleFunctionFactory& factory) {
factory.register_function<FunctionStrToDate>();
factory.register_function<FunctionStrToDatetime>();
factory.register_function<FunctionStrToDateV2>();
factory.register_function<FunctionStrToDatetimeV2>();
factory.register_function<FunctionMakeDate>();
factory.register_function<FromDays>();
factory.register_function<FunctionDateTruncDate>();