Skip to content

Commit

Permalink
[fix](datetime) Added datetime compatibility logic (apache#25791)
Browse files Browse the repository at this point in the history
  • Loading branch information
zclllyybb authored Oct 24, 2023
1 parent f23fdcb commit f9f5392
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions be/src/vec/functions/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ bool FunctionBuilderImpl::is_date_or_datetime_or_decimal(
func_return_type->is_nullable()
? ((DataTypeNullable*)func_return_type.get())->get_nested_type()
: func_return_type)) ||
(is_date_or_datetime(return_type->is_nullable()
? ((DataTypeNullable*)return_type.get())->get_nested_type()
: return_type) &&
is_date_v2_or_datetime_v2(
func_return_type->is_nullable()
? ((DataTypeNullable*)func_return_type.get())->get_nested_type()
: func_return_type)) ||
(is_decimal(return_type->is_nullable()
? ((DataTypeNullable*)return_type.get())->get_nested_type()
: return_type) &&
Expand Down
16 changes: 10 additions & 6 deletions be/src/vec/functions/function_timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1272,8 +1272,10 @@ class FunctionOtherTypesToDateType : public IFunction {
}
};

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>>;
Expand All @@ -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>();
Expand Down

0 comments on commit f9f5392

Please sign in to comment.