Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mryange committed Dec 17, 2024
1 parent 0603495 commit 111bb87
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 44 deletions.
61 changes: 22 additions & 39 deletions be/src/vec/functions/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,45 +296,28 @@ DataTypePtr FunctionBuilderImpl::get_return_type(const ColumnsWithTypeAndName& a

bool FunctionBuilderImpl::is_date_or_datetime_or_decimal(
const DataTypePtr& return_type, const DataTypePtr& func_return_type) const {
return (is_date_or_datetime(return_type->is_nullable()
? ((DataTypeNullable*)return_type.get())->get_nested_type()
: return_type) &&
is_date_or_datetime(
func_return_type->is_nullable()
? ((DataTypeNullable*)func_return_type.get())->get_nested_type()
: func_return_type)) ||
(is_date_v2_or_datetime_v2(
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)) ||
// For some date functions such as str_to_date(string, string), return_type will
// be datetimev2 if users enable datev2 but get_return_type(arguments) will still
// return datetime. We need keep backward compatibility here.
(is_date_v2_or_datetime_v2(
return_type->is_nullable()
? ((DataTypeNullable*)return_type.get())->get_nested_type()
: return_type) &&
is_date_or_datetime(
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) &&
is_decimal(func_return_type->is_nullable()
? ((DataTypeNullable*)func_return_type.get())->get_nested_type()
: func_return_type));
auto expect_return_type = remove_nullable(return_type);
auto real_return_type = remove_nullable(func_return_type);

auto check_date_and_datetime = [&]() -> bool {
return (is_date_or_datetime(expect_return_type) && is_date_or_datetime(real_return_type)) ||
(is_date_v2_or_datetime_v2(expect_return_type) &&
is_date_v2_or_datetime_v2(real_return_type));
};

// It is required that both types are either Decimal32, Decimal64, or Decimal128,
// and the scale must be the same. Due to differences between FE and BE code,
// no requirements are currently enforced for precision.

auto check_decimal = [&]() -> bool {
if (is_decimal(expect_return_type) && is_decimal(real_return_type)) {
return (expect_return_type->get_type_id() == real_return_type->get_type_id()) &&
(expect_return_type->get_scale() == real_return_type->get_scale());
}
return false;
};

return check_date_and_datetime() || check_decimal();
}

bool FunctionBuilderImpl::is_array_nested_type_date_or_datetime_or_decimal(
Expand Down
10 changes: 5 additions & 5 deletions be/src/vec/functions/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ class FunctionBuilderImpl : public IFunctionBuilder {
is_nothing(((DataTypeNullable*)func_return_type.get())->get_nested_type())) ||
is_date_or_datetime_or_decimal(return_type, func_return_type) ||
is_array_nested_type_date_or_datetime_or_decimal(return_type, func_return_type))) {
LOG_WARNING(
"function return type check failed, function_name={}, "
"expect_return_type={}, real_return_type={}, input_arguments={}",
get_name(), return_type->get_name(), func_return_type->get_name(),
get_types_string(arguments));
throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
"function return type check failed, function_name={}, "
"expect_return_type={}, real_return_type={}, input_arguments={}",
get_name(), return_type->get_name(),
func_return_type->get_name(), get_types_string(arguments));
return nullptr;
}
return build_impl(arguments, return_type);
Expand Down

0 comments on commit 111bb87

Please sign in to comment.