diff --git a/be/src/vec/data_types/data_type_date.h b/be/src/vec/data_types/data_type_date.h index 0df23022e2b6d2..077ce33c58f025 100644 --- a/be/src/vec/data_types/data_type_date.h +++ b/be/src/vec/data_types/data_type_date.h @@ -55,7 +55,7 @@ class DataTypeDate final : public DataTypeNumberBase { doris::FieldType get_storage_field_type() const override { return doris::FieldType::OLAP_FIELD_TYPE_DATE; } - const char* get_family_name() const override { return "DateTime"; } + const char* get_family_name() const override { return "Date"; } std::string do_get_name() const override { return "Date"; } bool equals(const IDataType& rhs) const override; diff --git a/be/src/vec/functions/array/function_array_apply.cpp b/be/src/vec/functions/array/function_array_apply.cpp index 4161441080aac0..bbd4dcd99c6b8c 100644 --- a/be/src/vec/functions/array/function_array_apply.cpp +++ b/be/src/vec/functions/array/function_array_apply.cpp @@ -65,6 +65,8 @@ class FunctionArrayApply : public IFunction { size_t get_number_of_arguments() const override { return 3; } ColumnNumbers get_arguments_that_are_always_constant() const override { return {1, 2}; } + bool has_return_type_in_signature() const override { return false; } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DCHECK(is_array(arguments[0])) << "first argument for function: " << name << " should be DataTypeArray" diff --git a/be/src/vec/functions/array/function_array_binary.h b/be/src/vec/functions/array/function_array_binary.h index 3a134e7392a40c..9519b3be17411c 100644 --- a/be/src/vec/functions/array/function_array_binary.h +++ b/be/src/vec/functions/array/function_array_binary.h @@ -36,6 +36,8 @@ class FunctionArrayBinary : public IFunction { bool is_variadic() const override { return false; } size_t get_number_of_arguments() const override { return 2; } + bool has_return_type_in_signature() const override { return false; } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DCHECK(is_array(arguments[0])) << arguments[0]->get_name(); DCHECK(is_array(arguments[1])) << arguments[1]->get_name(); diff --git a/be/src/vec/functions/array/function_array_compact.h b/be/src/vec/functions/array/function_array_compact.h index ef4ae5a76ad892..682a43777dd801 100644 --- a/be/src/vec/functions/array/function_array_compact.h +++ b/be/src/vec/functions/array/function_array_compact.h @@ -56,6 +56,8 @@ class FunctionArrayCompact : public IFunction { bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/array/function_array_concat.cpp b/be/src/vec/functions/array/function_array_concat.cpp index 18d0b7b48c14dc..431724f93e5052 100644 --- a/be/src/vec/functions/array/function_array_concat.cpp +++ b/be/src/vec/functions/array/function_array_concat.cpp @@ -54,6 +54,7 @@ class FunctionArrayConcat : public IFunction { String get_name() const override { return name; } bool is_variadic() const override { return true; } + bool has_return_type_in_signature() const override { return false; } size_t get_number_of_arguments() const override { return 1; } diff --git a/be/src/vec/functions/array/function_array_constructor.cpp b/be/src/vec/functions/array/function_array_constructor.cpp index 50c53697d2600d..1ace2f0fa4d134 100644 --- a/be/src/vec/functions/array/function_array_constructor.cpp +++ b/be/src/vec/functions/array/function_array_constructor.cpp @@ -62,6 +62,8 @@ class FunctionArrayConstructor : public IFunction { size_t get_number_of_arguments() const override { return 0; } + bool has_return_type_in_signature() const override { return false; } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { // we accept with empty argument, like array(), which will be treated as array(UInt8) if (arguments.empty()) { diff --git a/be/src/vec/functions/array/function_array_contains_all.cpp b/be/src/vec/functions/array/function_array_contains_all.cpp index c65ec57e3d6572..b920d34d951177 100644 --- a/be/src/vec/functions/array/function_array_contains_all.cpp +++ b/be/src/vec/functions/array/function_array_contains_all.cpp @@ -21,7 +21,9 @@ #include #include "common/status.h" +#include "vec/aggregate_functions/aggregate_function.h" #include "vec/common/assert_cast.h" +#include "vec/core/columns_with_type_and_name.h" #include "vec/data_types/data_type_array.h" #include "vec/data_types/data_type_number.h" #include "vec/functions/array/function_array_utils.h" @@ -42,18 +44,22 @@ class FunctionArrayContainsAll : public IFunction { size_t get_number_of_arguments() const override { return 2; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - auto left_data_type = remove_nullable(arguments[0]); - auto right_data_type = remove_nullable(arguments[1]); - DCHECK(is_array(left_data_type)) << arguments[0]->get_name(); - DCHECK(is_array(right_data_type)) << arguments[1]->get_name(); + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + auto left_data_type = remove_nullable(arguments[0].type); + auto right_data_type = remove_nullable(arguments[1].type); + DCHECK(is_array(left_data_type)) << arguments[0].type->get_name(); + DCHECK(is_array(right_data_type)) << arguments[1].type->get_name(); auto left_nested_type = remove_nullable( assert_cast(*left_data_type).get_nested_type()); auto right_nested_type = remove_nullable( assert_cast(*right_data_type).get_nested_type()); DCHECK(left_nested_type->equals(*right_nested_type)) - << "data type " << arguments[0]->get_name() << " not equal with " - << arguments[1]->get_name(); + << "data type " << arguments[0].type->get_name() << " not equal with " + << arguments[1].type->get_name(); + return std::make_shared(); + } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { return std::make_shared(); } diff --git a/be/src/vec/functions/array/function_array_cum_sum.cpp b/be/src/vec/functions/array/function_array_cum_sum.cpp index 5fba7d4a619bd5..bcd7350e04f67e 100644 --- a/be/src/vec/functions/array/function_array_cum_sum.cpp +++ b/be/src/vec/functions/array/function_array_cum_sum.cpp @@ -52,6 +52,8 @@ class FunctionArrayCumSum : public IFunction { bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/array/function_array_difference.h b/be/src/vec/functions/array/function_array_difference.h index 283ac206ce69b7..a371ccf60d3d48 100644 --- a/be/src/vec/functions/array/function_array_difference.h +++ b/be/src/vec/functions/array/function_array_difference.h @@ -64,6 +64,8 @@ class FunctionArrayDifference : public IFunction { bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 1; } bool use_default_implementation_for_nulls() const override { return true; } diff --git a/be/src/vec/functions/array/function_array_distinct.h b/be/src/vec/functions/array/function_array_distinct.h index 4d37f7cbcf7133..fd441fb52b9e7e 100644 --- a/be/src/vec/functions/array/function_array_distinct.h +++ b/be/src/vec/functions/array/function_array_distinct.h @@ -65,6 +65,8 @@ class FunctionArrayDistinct : public IFunction { bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/array/function_array_element.h b/be/src/vec/functions/array/function_array_element.h index e4b57348c883ae..869fcdfa837a9b 100644 --- a/be/src/vec/functions/array/function_array_element.h +++ b/be/src/vec/functions/array/function_array_element.h @@ -73,6 +73,8 @@ class FunctionArrayElement : public IFunction { bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + bool use_default_implementation_for_nulls() const override { return false; } size_t get_number_of_arguments() const override { return 2; } diff --git a/be/src/vec/functions/array/function_array_enumerate.cpp b/be/src/vec/functions/array/function_array_enumerate.cpp index 3846addb83bb55..1708086911e15e 100644 --- a/be/src/vec/functions/array/function_array_enumerate.cpp +++ b/be/src/vec/functions/array/function_array_enumerate.cpp @@ -57,6 +57,8 @@ class FunctionArrayEnumerate : public IFunction { static FunctionPtr create() { return std::make_shared(); } String get_name() const override { return name; } size_t get_number_of_arguments() const override { return 1; } + + bool has_return_type_in_signature() const override { return false; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { const DataTypeArray* array_type = check_and_get_data_type(remove_nullable(arguments[0]).get()); diff --git a/be/src/vec/functions/array/function_array_enumerate_uniq.cpp b/be/src/vec/functions/array/function_array_enumerate_uniq.cpp index bdee406655f196..44a38da9b45783 100644 --- a/be/src/vec/functions/array/function_array_enumerate_uniq.cpp +++ b/be/src/vec/functions/array/function_array_enumerate_uniq.cpp @@ -74,6 +74,7 @@ class FunctionArrayEnumerateUniq : public IFunction { String get_name() const override { return name; } bool is_variadic() const override { return true; } size_t get_number_of_arguments() const override { return 1; } + bool has_return_type_in_signature() const override { return false; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { if (arguments.empty()) { diff --git a/be/src/vec/functions/array/function_array_exists.cpp b/be/src/vec/functions/array/function_array_exists.cpp index 8621ecd35c0280..14acb0eaa9cb70 100644 --- a/be/src/vec/functions/array/function_array_exists.cpp +++ b/be/src/vec/functions/array/function_array_exists.cpp @@ -56,6 +56,8 @@ class FunctionArrayExists : public IFunction { size_t get_number_of_arguments() const override { return 1; } + bool has_return_type_in_signature() const override { return false; } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DCHECK(is_array(arguments[0])) << "first argument for function: " << name << " should be DataTypeArray" diff --git a/be/src/vec/functions/array/function_array_filter.cpp b/be/src/vec/functions/array/function_array_filter.cpp index 1a9cc5105b0f58..0c1a3a13a6b917 100644 --- a/be/src/vec/functions/array/function_array_filter.cpp +++ b/be/src/vec/functions/array/function_array_filter.cpp @@ -52,6 +52,7 @@ class FunctionArrayFilter : public IFunction { String get_name() const override { return name; } bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } size_t get_number_of_arguments() const override { return 2; } diff --git a/be/src/vec/functions/array/function_array_index.h b/be/src/vec/functions/array/function_array_index.h index e602d67a73b01c..a3e388bce04887 100644 --- a/be/src/vec/functions/array/function_array_index.h +++ b/be/src/vec/functions/array/function_array_index.h @@ -40,6 +40,7 @@ #include "vec/core/block.h" #include "vec/core/column_numbers.h" #include "vec/core/column_with_type_and_name.h" +#include "vec/core/columns_with_type_and_name.h" #include "vec/core/types.h" #include "vec/data_types/data_type.h" #include "vec/data_types/data_type_array.h" @@ -182,14 +183,18 @@ class FunctionArrayIndex : public IFunction { return Status::OK(); } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - if (arguments[0]->is_nullable()) { + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + if (arguments[0].type->is_nullable()) { return make_nullable(std::make_shared>()); } else { return std::make_shared>(); } } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared>(); + } + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) const override { DBUG_EXECUTE_IF("array_func.array_contains", { diff --git a/be/src/vec/functions/array/function_array_join.h b/be/src/vec/functions/array/function_array_join.h index 29521c36111824..468ee51588d731 100644 --- a/be/src/vec/functions/array/function_array_join.h +++ b/be/src/vec/functions/array/function_array_join.h @@ -16,8 +16,12 @@ // under the License. #pragma once +#include + #include "vec/columns/column_array.h" #include "vec/columns/column_const.h" +#include "vec/core/columns_with_type_and_name.h" +#include "vec/data_types/data_type.h" #include "vec/data_types/data_type_array.h" #include "vec/data_types/data_type_number.h" #include "vec/data_types/data_type_string.h" @@ -55,6 +59,10 @@ struct ArrayJoinImpl { return std::make_shared(); } + static DataTypePtr get_return_type_impl(const DataTypes& arguments) { + return std::make_shared(); + } + static Status execute(Block& block, const ColumnNumbers& arguments, uint32_t result, const DataTypeArray* data_type_array, const ColumnArray& array) { ColumnPtr src_column = diff --git a/be/src/vec/functions/array/function_array_mapped.h b/be/src/vec/functions/array/function_array_mapped.h index 5c84baf9dfadb8..44fb564f4ee9ac 100644 --- a/be/src/vec/functions/array/function_array_mapped.h +++ b/be/src/vec/functions/array/function_array_mapped.h @@ -46,6 +46,8 @@ class FunctionArrayMapped : public IFunction { static constexpr auto name = Name::name; static FunctionPtr create() { return std::make_shared(); } + bool has_return_type_in_signature() const override { return false; } + String get_name() const override { return name; } Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) const override { diff --git a/be/src/vec/functions/array/function_array_nary.h b/be/src/vec/functions/array/function_array_nary.h index e9b2009f68484c..ca79b52a519a2e 100644 --- a/be/src/vec/functions/array/function_array_nary.h +++ b/be/src/vec/functions/array/function_array_nary.h @@ -37,6 +37,8 @@ class FunctionArrayNary : public IFunction { bool is_variadic() const override { return true; } size_t get_number_of_arguments() const override { return 0; } + bool has_return_type_in_signature() const override { return false; } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DCHECK(arguments.size() >= 2) << "function: " << get_name() << ", arguments should large equals than 2"; diff --git a/be/src/vec/functions/array/function_array_pop.cpp b/be/src/vec/functions/array/function_array_pop.cpp index 1ddd767cfaf3ce..9be15f3947b021 100644 --- a/be/src/vec/functions/array/function_array_pop.cpp +++ b/be/src/vec/functions/array/function_array_pop.cpp @@ -54,6 +54,7 @@ class FunctionArrayPop : public IFunction { bool is_variadic() const override { return false; } size_t get_number_of_arguments() const override { return 1; } + bool has_return_type_in_signature() const override { return false; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DCHECK(is_array(arguments[0])) diff --git a/be/src/vec/functions/array/function_array_pushback.cpp b/be/src/vec/functions/array/function_array_pushback.cpp index d1152ca9739b98..f3bc715b9c8e97 100644 --- a/be/src/vec/functions/array/function_array_pushback.cpp +++ b/be/src/vec/functions/array/function_array_pushback.cpp @@ -51,6 +51,7 @@ class FunctionArrayPushback : public IFunction { String get_name() const override { return name; } bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } size_t get_number_of_arguments() const override { return 2; } diff --git a/be/src/vec/functions/array/function_array_pushfront.cpp b/be/src/vec/functions/array/function_array_pushfront.cpp index c592999b108a35..3b36d29e9ee8c8 100644 --- a/be/src/vec/functions/array/function_array_pushfront.cpp +++ b/be/src/vec/functions/array/function_array_pushfront.cpp @@ -54,6 +54,7 @@ class FunctionArrayPushfront : public IFunction { bool is_variadic() const override { return false; } size_t get_number_of_arguments() const override { return 2; } + bool has_return_type_in_signature() const override { return false; } bool use_default_implementation_for_nulls() const override { return false; } diff --git a/be/src/vec/functions/array/function_array_remove.h b/be/src/vec/functions/array/function_array_remove.h index 661a18170ed9dc..aa6ac4e1180ef8 100644 --- a/be/src/vec/functions/array/function_array_remove.h +++ b/be/src/vec/functions/array/function_array_remove.h @@ -63,6 +63,8 @@ class FunctionArrayRemove : public IFunction { bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 2; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/array/function_array_shuffle.cpp b/be/src/vec/functions/array/function_array_shuffle.cpp index b9e3206ba0baa1..a9852147567e7d 100644 --- a/be/src/vec/functions/array/function_array_shuffle.cpp +++ b/be/src/vec/functions/array/function_array_shuffle.cpp @@ -57,6 +57,8 @@ class FunctionArrayShuffle : public IFunction { bool is_variadic() const override { return true; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/array/function_array_slice.h b/be/src/vec/functions/array/function_array_slice.h index 76082b266026ea..aed499c506b34c 100644 --- a/be/src/vec/functions/array/function_array_slice.h +++ b/be/src/vec/functions/array/function_array_slice.h @@ -51,6 +51,8 @@ class FunctionArraySlice : public IFunction { bool is_variadic() const override { return true; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 0; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/array/function_array_sort.h b/be/src/vec/functions/array/function_array_sort.h index 7b66336836ea12..8a2e2622f8be20 100644 --- a/be/src/vec/functions/array/function_array_sort.h +++ b/be/src/vec/functions/array/function_array_sort.h @@ -53,6 +53,8 @@ class FunctionArraySort : public IFunction { bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/array/function_array_sortby.cpp b/be/src/vec/functions/array/function_array_sortby.cpp index fe6799aaa2e876..fdf93c3a1b145c 100644 --- a/be/src/vec/functions/array/function_array_sortby.cpp +++ b/be/src/vec/functions/array/function_array_sortby.cpp @@ -58,6 +58,8 @@ class FunctionArraySortBy : public IFunction { bool use_default_implementation_for_nulls() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DCHECK(is_array(remove_nullable(arguments[0]))) << "first argument for function: " << name << " should be DataTypeArray" diff --git a/be/src/vec/functions/array/function_array_split.cpp b/be/src/vec/functions/array/function_array_split.cpp index 5e58a9f189a657..e2961442344596 100644 --- a/be/src/vec/functions/array/function_array_split.cpp +++ b/be/src/vec/functions/array/function_array_split.cpp @@ -55,6 +55,7 @@ class FunctionArraySplit : public IFunction { String get_name() const override { return name; } size_t get_number_of_arguments() const override { return 2; } + bool has_return_type_in_signature() const override { return false; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { return std::make_shared(make_nullable(arguments[0])); diff --git a/be/src/vec/functions/array/function_array_with_constant.cpp b/be/src/vec/functions/array/function_array_with_constant.cpp index 7b9f3b43271f05..c764a04eff3ebe 100644 --- a/be/src/vec/functions/array/function_array_with_constant.cpp +++ b/be/src/vec/functions/array/function_array_with_constant.cpp @@ -66,6 +66,7 @@ class FunctionArrayWithConstant : public IFunction { bool is_variadic() const override { return false; } size_t get_number_of_arguments() const override { return 2; } + bool has_return_type_in_signature() const override { return false; } // need handle null cases bool use_default_implementation_for_nulls() const override { return false; } diff --git a/be/src/vec/functions/array/function_array_zip.cpp b/be/src/vec/functions/array/function_array_zip.cpp index 217a8039421a1c..f0e90fe998a7b4 100644 --- a/be/src/vec/functions/array/function_array_zip.cpp +++ b/be/src/vec/functions/array/function_array_zip.cpp @@ -60,6 +60,7 @@ class FunctionArrayZip : public IFunction { public: static constexpr auto name = "array_zip"; static FunctionPtr create() { return std::make_shared(); } + bool has_return_type_in_signature() const override { return false; } /// Get function name. String get_name() const override { return name; } diff --git a/be/src/vec/functions/array/function_arrays_overlap.h b/be/src/vec/functions/array/function_arrays_overlap.h index 8ac21bcd710f8d..a5db0aec135cad 100644 --- a/be/src/vec/functions/array/function_arrays_overlap.h +++ b/be/src/vec/functions/array/function_arrays_overlap.h @@ -37,6 +37,7 @@ #include "vec/core/block.h" #include "vec/core/column_numbers.h" #include "vec/core/column_with_type_and_name.h" +#include "vec/core/columns_with_type_and_name.h" #include "vec/core/types.h" #include "vec/data_types/data_type.h" #include "vec/data_types/data_type_array.h" @@ -113,21 +114,25 @@ class FunctionArraysOverlap : public IFunction { size_t get_number_of_arguments() const override { return 2; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - auto left_data_type = remove_nullable(arguments[0]); - auto right_data_type = remove_nullable(arguments[1]); - DCHECK(is_array(left_data_type)) << arguments[0]->get_name(); - DCHECK(is_array(right_data_type)) << arguments[1]->get_name(); + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + auto left_data_type = remove_nullable(arguments[0].type); + auto right_data_type = remove_nullable(arguments[1].type); + DCHECK(is_array(left_data_type)) << arguments[0].type->get_name(); + DCHECK(is_array(right_data_type)) << arguments[1].type->get_name(); auto left_nested_type = remove_nullable( assert_cast(*left_data_type).get_nested_type()); auto right_nested_type = remove_nullable( assert_cast(*right_data_type).get_nested_type()); DCHECK(left_nested_type->equals(*right_nested_type)) - << "data type " << arguments[0]->get_name() << " not equal with " - << arguments[1]->get_name(); + << "data type " << arguments[0].type->get_name() << " not equal with " + << arguments[1].type->get_name(); return make_nullable(std::make_shared()); } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(); + } + /** * eval inverted index. we can filter array rows with inverted index iter * array_overlap(array, []) -> array_overlap(array, const value) diff --git a/be/src/vec/functions/function.cpp b/be/src/vec/functions/function.cpp index 851e430d2f0407..c5b43f05ced6f9 100644 --- a/be/src/vec/functions/function.cpp +++ b/be/src/vec/functions/function.cpp @@ -294,42 +294,9 @@ DataTypePtr FunctionBuilderImpl::get_return_type(const ColumnsWithTypeAndName& a return get_return_type_without_low_cardinality(arguments); } -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() +bool FunctionBuilderImpl::is_type_decimal(const DataTypePtr& return_type, + const DataTypePtr& func_return_type) const { + return (is_decimal(return_type->is_nullable() ? ((DataTypeNullable*)return_type.get())->get_nested_type() : return_type) && is_decimal(func_return_type->is_nullable() @@ -337,8 +304,8 @@ bool FunctionBuilderImpl::is_date_or_datetime_or_decimal( : func_return_type)); } -bool FunctionBuilderImpl::is_array_nested_type_date_or_datetime_or_decimal( - const DataTypePtr& return_type, const DataTypePtr& func_return_type) const { +bool FunctionBuilderImpl::is_array_nested_type_decimal(const DataTypePtr& return_type, + const DataTypePtr& func_return_type) const { auto return_type_ptr = return_type->is_nullable() ? ((DataTypeNullable*)return_type.get())->get_nested_type() : return_type; @@ -360,7 +327,7 @@ bool FunctionBuilderImpl::is_array_nested_type_date_or_datetime_or_decimal( ((DataTypeNullable*)(nested_nullable_return_type_ptr.get()))->get_nested_type(); auto nested_func_return_type_ptr = ((DataTypeNullable*)(nested_nullable_func_return_type.get()))->get_nested_type(); - return is_date_or_datetime_or_decimal(nested_return_type_ptr, nested_func_return_type_ptr); + return is_type_decimal(nested_return_type_ptr, nested_func_return_type_ptr); } return false; } diff --git a/be/src/vec/functions/function.h b/be/src/vec/functions/function.h index 92282c483948e6..5050070e4efe1b 100644 --- a/be/src/vec/functions/function.h +++ b/be/src/vec/functions/function.h @@ -237,6 +237,11 @@ class IFunctionBuilder { virtual FunctionBasePtr build(const ColumnsWithTypeAndName& arguments, const DataTypePtr& return_type) const = 0; + // if a function's get_variadic_argument_types() not override and get_return_type_impl() + // result is rely on arguments, the function should override return false + // more information see https://github.com/apache/doris/pull/45159 + virtual bool has_return_type_in_signature() const = 0; + /// For higher-order functions (functions, that have lambda expression as at least one argument). /// You pass data types with empty DataTypeFunction for lambda arguments. /// This function will replace it with DataTypeFunction containing actual types. @@ -272,8 +277,8 @@ class FunctionBuilderImpl : public IFunctionBuilder { // Nullable when `use_default_implementation_for_nulls` is true. (return_type->is_nullable() && func_return_type->is_nullable() && 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))) { + is_type_decimal(return_type, func_return_type) || + is_array_nested_type_decimal(return_type, func_return_type))) { LOG_WARNING( "function return type check failed, function_name={}, " "expect_return_type={}, real_return_type={}, input_arguments={}", @@ -299,6 +304,8 @@ class FunctionBuilderImpl : public IFunctionBuilder { ColumnNumbers get_arguments_that_are_always_constant() const override { return {}; } + bool has_return_type_in_signature() const override { return true; } + protected: // Get the result type by argument type. If the function does not apply to these arguments, throw an exception. // the get_return_type_impl and its overrides should only return the nested type if `use_default_implementation_for_nulls` is true. @@ -342,13 +349,14 @@ class FunctionBuilderImpl : public IFunctionBuilder { virtual DataTypes get_variadic_argument_types_impl() const { return {}; } private: + friend class SimpleFunctionFactory; + DataTypePtr get_return_type_without_low_cardinality( const ColumnsWithTypeAndName& arguments) const; - bool is_date_or_datetime_or_decimal(const DataTypePtr& return_type, - const DataTypePtr& func_return_type) const; - bool is_array_nested_type_date_or_datetime_or_decimal( - const DataTypePtr& return_type, const DataTypePtr& func_return_type) const; + bool is_type_decimal(const DataTypePtr& return_type, const DataTypePtr& func_return_type) const; + bool is_array_nested_type_decimal(const DataTypePtr& return_type, + const DataTypePtr& func_return_type) const; }; /// Previous function interface. @@ -532,6 +540,9 @@ class DefaultFunctionBuilder : public FunctionBuilderImpl { String get_name() const override { return function->get_name(); } bool is_variadic() const override { return function->is_variadic(); } + bool has_return_type_in_signature() const override { + return function->has_return_type_in_signature(); + } size_t get_number_of_arguments() const override { return function->get_number_of_arguments(); } ColumnNumbers get_arguments_that_are_always_constant() const override { diff --git a/be/src/vec/functions/function_binary_arithmetic.h b/be/src/vec/functions/function_binary_arithmetic.h index a2757b38346247..bde905b355a5dc 100644 --- a/be/src/vec/functions/function_binary_arithmetic.h +++ b/be/src/vec/functions/function_binary_arithmetic.h @@ -978,6 +978,8 @@ class FunctionBinaryArithmetic : public IFunction { size_t get_number_of_arguments() const override { return 2; } + bool has_return_type_in_signature() const override { return false; } + DataTypes get_variadic_argument_types_impl() const override { if constexpr (OpTraits::has_variadic_argument) { return OpTraits::Op::get_variadic_argument_types(); diff --git a/be/src/vec/functions/function_case.h b/be/src/vec/functions/function_case.h index 81f08f682ef0ef..d7416a77392f2f 100644 --- a/be/src/vec/functions/function_case.h +++ b/be/src/vec/functions/function_case.h @@ -127,6 +127,7 @@ class FunctionCase : public IFunction { static constexpr auto name = FunctionCaseName::name; static FunctionPtr create() { return std::make_shared(); } String get_name() const override { return name; } + bool has_return_type_in_signature() const override { return false; } size_t get_number_of_arguments() const override { return 0; } bool is_variadic() const override { return true; } diff --git a/be/src/vec/functions/function_cast.h b/be/src/vec/functions/function_cast.h index 483e837de5dfd8..f4bb98ca66dd03 100644 --- a/be/src/vec/functions/function_cast.h +++ b/be/src/vec/functions/function_cast.h @@ -1146,7 +1146,7 @@ class FunctionConvert : public IFunction { // This function should not be called for get DateType Ptr // using the FunctionCast::get_return_type_impl - DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + DataTypePtr get_return_type_impl(const DataTypes& types) const override { return std::make_shared(); } @@ -1471,7 +1471,7 @@ class FunctionConvertFromString : public IFunction { // This function should not be called for get DateType Ptr // using the FunctionCast::get_return_type_impl - DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + DataTypePtr get_return_type_impl(const DataTypes& types) const override { DataTypePtr res; if constexpr (IsDataTypeDecimal) { auto error_type = std::make_shared(); @@ -1517,7 +1517,7 @@ class FunctionConvertToTimeType : public IFunction { // This function should not be called for get DateType Ptr // using the FunctionCast::get_return_type_impl - DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { return std::make_shared(); } @@ -2369,6 +2369,8 @@ class FunctionBuilderCast : public FunctionBuilderImpl { ColumnNumbers get_arguments_that_are_always_constant() const override { return {1}; } + bool has_return_type_in_signature() const override { return false; } + protected: FunctionBasePtr build_impl(const ColumnsWithTypeAndName& arguments, const DataTypePtr& return_type) const override { @@ -2388,16 +2390,7 @@ class FunctionBuilderCast : public FunctionBuilderImpl { // 2. from_type is string, to_type is not string need_to_be_nullable |= (arguments[0].type->get_type_id() == TypeIndex::String) && (type->get_type_id() != TypeIndex::String); - // 3. from_type is not DateTime/Date, to_type is DateTime/Date - need_to_be_nullable |= (arguments[0].type->get_type_id() != TypeIndex::Date && - arguments[0].type->get_type_id() != TypeIndex::DateTime) && - (type->get_type_id() == TypeIndex::Date || - type->get_type_id() == TypeIndex::DateTime); - // 4. from_type is not DateTimeV2/DateV2, to_type is DateTimeV2/DateV2 - need_to_be_nullable |= (arguments[0].type->get_type_id() != TypeIndex::DateV2 && - arguments[0].type->get_type_id() != TypeIndex::DateTimeV2) && - (type->get_type_id() == TypeIndex::DateV2 || - type->get_type_id() == TypeIndex::DateTimeV2); + if (need_to_be_nullable && !type->is_nullable()) { return make_nullable(type); } diff --git a/be/src/vec/functions/function_coalesce.cpp b/be/src/vec/functions/function_coalesce.cpp index 6e5db15d160c06..64540aee0e3ec6 100644 --- a/be/src/vec/functions/function_coalesce.cpp +++ b/be/src/vec/functions/function_coalesce.cpp @@ -62,6 +62,8 @@ class FunctionCoalesce : public IFunction { String get_name() const override { return name; } + bool has_return_type_in_signature() const override { return false; } + bool use_default_implementation_for_nulls() const override { return false; } bool is_variadic() const override { return true; } diff --git a/be/src/vec/functions/function_date_or_datetime_computation.cpp b/be/src/vec/functions/function_date_or_datetime_computation.cpp index ece897d6dcbf7c..d8d20a6ee87fc0 100644 --- a/be/src/vec/functions/function_date_or_datetime_computation.cpp +++ b/be/src/vec/functions/function_date_or_datetime_computation.cpp @@ -21,24 +21,54 @@ namespace doris::vectorized { -using FunctionAddSeconds = FunctionDateOrDateTimeComputation>; -using FunctionAddMinutes = FunctionDateOrDateTimeComputation>; -using FunctionAddHours = FunctionDateOrDateTimeComputation>; -using FunctionAddDays = FunctionDateOrDateTimeComputation>; -using FunctionAddWeeks = FunctionDateOrDateTimeComputation>; -using FunctionAddMonths = FunctionDateOrDateTimeComputation>; -using FunctionAddQuarters = FunctionDateOrDateTimeComputation>; -using FunctionAddYears = FunctionDateOrDateTimeComputation>; - -using FunctionSubSeconds = FunctionDateOrDateTimeComputation>; -using FunctionSubMinutes = FunctionDateOrDateTimeComputation>; -using FunctionSubHours = FunctionDateOrDateTimeComputation>; -using FunctionSubDays = FunctionDateOrDateTimeComputation>; -using FunctionSubWeeks = FunctionDateOrDateTimeComputation>; -using FunctionSubMonths = FunctionDateOrDateTimeComputation>; -using FunctionSubQuarters = +using FunctionDatetimeAddSeconds = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeAddMinutes = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeAddHours = FunctionDateOrDateTimeComputation>; +using FunctionDatetimeAddDays = FunctionDateOrDateTimeComputation>; +using FunctionDatetimeAddWeeks = FunctionDateOrDateTimeComputation>; +using FunctionDatetimeAddMonths = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeAddQuarters = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeAddYears = FunctionDateOrDateTimeComputation>; + +using FunctionDateAddSeconds = FunctionDateOrDateTimeComputation>; +using FunctionDateAddMinutes = FunctionDateOrDateTimeComputation>; +using FunctionDateAddHours = FunctionDateOrDateTimeComputation>; +using FunctionDateAddDays = FunctionDateOrDateTimeComputation>; +using FunctionDateAddWeeks = FunctionDateOrDateTimeComputation>; +using FunctionDateAddMonths = FunctionDateOrDateTimeComputation>; +using FunctionDateAddQuarters = FunctionDateOrDateTimeComputation>; +using FunctionDateAddYears = FunctionDateOrDateTimeComputation>; + +using FunctionDatetimeSubSeconds = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeSubMinutes = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeSubHours = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeSubDays = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeSubWeeks = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeSubMonths = + FunctionDateOrDateTimeComputation>; +using FunctionDatetimeSubQuarters = FunctionDateOrDateTimeComputation>; -using FunctionSubYears = FunctionDateOrDateTimeComputation>; +using FunctionDatetimeSubYears = + FunctionDateOrDateTimeComputation>; + +using FunctionDateSubSeconds = FunctionDateOrDateTimeComputation>; +using FunctionDateSubMinutes = FunctionDateOrDateTimeComputation>; +using FunctionDateSubHours = FunctionDateOrDateTimeComputation>; +using FunctionDateSubDays = FunctionDateOrDateTimeComputation>; +using FunctionDateSubWeeks = FunctionDateOrDateTimeComputation>; +using FunctionDateSubMonths = FunctionDateOrDateTimeComputation>; +using FunctionDateSubQuarters = + FunctionDateOrDateTimeComputation>; +using FunctionDateSubYears = FunctionDateOrDateTimeComputation>; using FunctionDateDiff = FunctionDateOrDateTimeComputation>; @@ -95,23 +125,41 @@ using FunctionMilliSecToDateTime = TimestampToDateTime; using FunctionSecToDateTime = TimestampToDateTime; void register_function_date_time_computation(SimpleFunctionFactory& factory) { - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); factory.register_function(); factory.register_function(); diff --git a/be/src/vec/functions/function_date_or_datetime_computation.h b/be/src/vec/functions/function_date_or_datetime_computation.h index df7dc20a312ea3..3ee57f5ac48def 100644 --- a/be/src/vec/functions/function_date_or_datetime_computation.h +++ b/be/src/vec/functions/function_date_or_datetime_computation.h @@ -75,7 +75,8 @@ ReturnNativeType date_time_add(const InputNativeType& t, Int32 delta, bool& is_n // e.g.: for DatatypeDatetimeV2, cast from u64 to DateV2Value auto ts_value = binary_cast(t); TimeInterval interval(unit, delta, false); - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v || + std::is_same_v) { is_null = !(ts_value.template date_add_interval(interval)); // here DateValueType = ResultDateValueType return binary_cast(ts_value); @@ -88,32 +89,43 @@ ReturnNativeType date_time_add(const InputNativeType& t, Int32 delta, bool& is_n } } -#define ADD_TIME_FUNCTION_IMPL(CLASS, NAME, UNIT) \ - template \ - struct CLASS { \ - /* for V1 type all return Datetime. for V2 type, if unit <= hour, increase to DatetimeV2 */ \ - using ReturnType = std::conditional_t< \ - date_cast::IsV1(), DataTypeDateTime, \ - std::conditional_t< \ - std::is_same_v, \ - std::conditional_t, \ - DataTypeDateTimeV2>>; \ - using ReturnNativeType = ReturnType::FieldType; \ - using InputNativeType = ArgType::FieldType; \ - static constexpr auto name = #NAME; \ - static constexpr auto is_nullable = true; \ - static inline ReturnNativeType execute(const InputNativeType& t, Int32 delta, \ - bool& is_null) { \ - return date_time_add(t, delta, is_null); \ - } \ - \ - static DataTypes get_variadic_argument_types() { \ - return {std::make_shared(), std::make_shared()}; \ - } \ +#define ADD_TIME_FUNCTION_IMPL(CLASS, NAME, UNIT) \ + template \ + struct CLASS { \ + /*for V2 type, if unit <= hour, increase to DatetimeV2, for V1 same as V2 version*/ \ + using ReturnType = std::conditional_t< \ + date_cast::IsV1(), \ + std::conditional_t< \ + std::is_same_v, \ + std::conditional_t, \ + DataTypeDateTime>, \ + std::conditional_t< \ + std::is_same_v, \ + std::conditional_t, \ + DataTypeDateTimeV2>>; \ + static bool has_return_type_in_signature() { \ + return true; \ + } \ + using ReturnNativeType = ReturnType::FieldType; \ + using InputNativeType = ArgType::FieldType; \ + static constexpr auto name = #NAME; \ + static constexpr auto is_nullable = true; \ + static inline ReturnNativeType execute(const InputNativeType& t, Int32 delta, \ + bool& is_null) { \ + return date_time_add(t, delta, is_null); \ + } \ + \ + static DataTypes get_variadic_argument_types() { \ + return {std::make_shared(), std::make_shared()}; \ + } \ } ADD_TIME_FUNCTION_IMPL(AddMicrosecondsImpl, microseconds_add, MICROSECOND); @@ -138,6 +150,8 @@ struct AddQuartersImpl { using ReturnNativeType = ReturnType::FieldType; static constexpr auto name = "quarters_add"; static constexpr auto is_nullable = true; + + static bool has_return_type_in_signature() { return true; } static inline ReturnNativeType execute(const InputNativeType& t, Int32 delta, bool& is_null) { return date_time_add(t, 3 * delta, is_null); } @@ -151,6 +165,7 @@ template struct SubtractIntervalImpl { using ReturnType = typename Transform::ReturnType; using InputNativeType = typename Transform::InputNativeType; + static bool has_return_type_in_signature() { return Transform::has_return_type_in_signature(); } using ReturnNativeType = typename Transform::ReturnNativeType; static constexpr auto is_nullable = true; static inline ReturnNativeType execute(const InputNativeType& t, Int32 delta, bool& is_null) { @@ -220,6 +235,9 @@ struct SubtractYearsImpl : SubtractIntervalImpl, DateType using DateValueType1 = date_cast::TypeToValueTypeV; \ using DateValueType2 = date_cast::TypeToValueTypeV; \ using ReturnType = RETURN_TYPE; \ + static bool has_return_type_in_signature() { \ + return true; \ + } \ \ static constexpr auto name = #FN_NAME; \ static constexpr auto is_nullable = false; \ @@ -247,6 +265,7 @@ struct TimeDiffImpl { static constexpr bool UsingTimev2 = date_cast::IsV2() || date_cast::IsV2(); + static bool has_return_type_in_signature() { return true; } using ReturnType = DataTypeTimeV2; // TimeV1Type also use double as native type. same as v2. static constexpr auto name = "timediff"; @@ -295,6 +314,9 @@ TIME_DIFF_FUNCTION_IMPL(MicroSecondsDiffImpl, microseconds_diff, MICROSECOND); using ArgType = DateType::FieldType; \ using DateValueType = date_cast::TypeToValueTypeV; \ using ReturnType = RETURN_TYPE; \ + static bool has_return_type_in_signature() { \ + return true; \ + } \ \ static constexpr auto name = #NAME; \ static constexpr auto is_nullable = false; \ @@ -421,6 +443,10 @@ class FunctionDateOrDateTimeComputation : public IFunction { String get_name() const override { return name; } + bool has_return_type_in_signature() const override { + return Transform::has_return_type_in_signature(); + } + bool is_variadic() const override { return true; } size_t get_number_of_arguments() const override { return 0; } @@ -436,6 +462,10 @@ class FunctionDateOrDateTimeComputation : public IFunction { RETURN_REAL_TYPE_FOR_DATEV2_FUNCTION(typename Transform::ReturnType); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) const override { const auto& first_arg_type = block.get_by_position(arguments[0]).type; @@ -621,6 +651,10 @@ class FunctionCurrentDateOrDateTime : public IFunction { return std::make_shared(); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + bool is_variadic() const override { return true; } DataTypes get_variadic_argument_types_impl() const override { @@ -641,6 +675,7 @@ struct CurrentDateTimeImpl { static constexpr auto name = FunctionName::name; using ReturnType = std::conditional_t; + static bool has_return_type_in_signature() { return true; } static DataTypes get_variadic_argument_types() { if constexpr (WithPrecision) { return {std::make_shared()}; @@ -873,6 +908,10 @@ struct TimestampToDateTime : IFunction { return make_nullable(std::make_shared()); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + static FunctionPtr create() { return std::make_shared>(); } Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, @@ -965,10 +1004,7 @@ class CurrentDateFunctionBuilder : public FunctionBuilderImpl { protected: DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - return make_nullable(std::make_shared()); - } - DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { - return make_nullable(std::make_shared()); + return std::make_shared(); } bool use_default_implementation_for_nulls() const override { return false; } diff --git a/be/src/vec/functions/function_date_or_datetime_computation_v2.cpp b/be/src/vec/functions/function_date_or_datetime_computation_v2.cpp index db43bf1818d38f..1c74abbf2b9cb9 100644 --- a/be/src/vec/functions/function_date_or_datetime_computation_v2.cpp +++ b/be/src/vec/functions/function_date_or_datetime_computation_v2.cpp @@ -21,28 +21,32 @@ namespace doris::vectorized { -using FunctionAddSecondsV2 = FunctionDateOrDateTimeComputation>; -using FunctionAddMinutesV2 = FunctionDateOrDateTimeComputation>; -using FunctionAddHoursV2 = FunctionDateOrDateTimeComputation>; -using FunctionAddDaysV2 = FunctionDateOrDateTimeComputation>; -using FunctionAddWeeksV2 = FunctionDateOrDateTimeComputation>; -using FunctionAddMonthsV2 = FunctionDateOrDateTimeComputation>; -using FunctionAddQuartersV2 = FunctionDateOrDateTimeComputation>; -using FunctionAddYearsV2 = FunctionDateOrDateTimeComputation>; - -using FunctionSubSecondsV2 = FunctionDateOrDateTimeComputation>; -using FunctionSubMinutesV2 = FunctionDateOrDateTimeComputation>; -using FunctionSubHoursV2 = FunctionDateOrDateTimeComputation>; -using FunctionSubDaysV2 = FunctionDateOrDateTimeComputation>; -using FunctionSubWeeksV2 = FunctionDateOrDateTimeComputation>; -using FunctionSubMonthsV2 = FunctionDateOrDateTimeComputation>; -using FunctionSubQuartersV2 = +using FunctionDateAddSecondsV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateAddMinutesV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateAddHoursV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateAddDaysV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateAddWeeksV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateAddMonthsV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateAddQuartersV2 = + FunctionDateOrDateTimeComputation>; +using FunctionDateAddYearsV2 = FunctionDateOrDateTimeComputation>; + +using FunctionDateSubSecondsV2 = + FunctionDateOrDateTimeComputation>; +using FunctionDateSubMinutesV2 = + FunctionDateOrDateTimeComputation>; +using FunctionDateSubHoursV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateSubDaysV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateSubWeeksV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateSubMonthsV2 = + FunctionDateOrDateTimeComputation>; +using FunctionDateSubQuartersV2 = FunctionDateOrDateTimeComputation>; -using FunctionSubYearsV2 = FunctionDateOrDateTimeComputation>; +using FunctionDateSubYearsV2 = FunctionDateOrDateTimeComputation>; -using FunctionToYearWeekTwoArgsV2 = +using FunctionDateToYearWeekTwoArgsV2 = FunctionDateOrDateTimeComputation>; -using FunctionToWeekTwoArgsV2 = +using FunctionDateToWeekTwoArgsV2 = FunctionDateOrDateTimeComputation>; using FunctionDatetimeV2AddMicroseconds = @@ -114,14 +118,14 @@ using FunctionDatetimeV2ToWeekTwoArgs = FunctionDateOrDateTimeComputation>; void register_function_date_time_computation_v2(SimpleFunctionFactory& factory) { - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); factory.register_function(); factory.register_function(); @@ -134,14 +138,14 @@ void register_function_date_time_computation_v2(SimpleFunctionFactory& factory) factory.register_function(); factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); - factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); + factory.register_function(); factory.register_function(); factory.register_function(); @@ -175,8 +179,8 @@ void register_function_date_time_computation_v2(SimpleFunctionFactory& factory) REGISTER_ALL_DATEV2_FUNCTIONS_WITH_TWO_ARGS(FunctionDatetimeV2MilliSecondsDiff) REGISTER_ALL_DATEV2_FUNCTIONS_WITH_TWO_ARGS(FunctionDatetimeV2MicroSecondsDiff) - factory.register_function(); - factory.register_function(); + factory.register_function(); + factory.register_function(); factory.register_function(); factory.register_function(); } diff --git a/be/src/vec/functions/function_date_or_datetime_to_something.h b/be/src/vec/functions/function_date_or_datetime_to_something.h index 2bc96cc7e937d7..6424fca9eb1d0e 100644 --- a/be/src/vec/functions/function_date_or_datetime_to_something.h +++ b/be/src/vec/functions/function_date_or_datetime_to_something.h @@ -20,6 +20,7 @@ #pragma once +#include "vec/aggregate_functions/aggregate_function.h" #include "vec/data_types/data_type_date.h" #include "vec/functions/date_time_transforms.h" #include "vec/functions/function.h" @@ -90,6 +91,10 @@ class FunctionDateOrDateTimeToSomething : public IFunction { RETURN_REAL_TYPE_FOR_DATEV2_FUNCTION(ToDataType); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + ColumnNumbers get_arguments_that_are_always_constant() const override { return {1}; } bool use_default_implementation_for_nulls() const override { return false; } diff --git a/be/src/vec/functions/function_date_or_datetime_to_string.h b/be/src/vec/functions/function_date_or_datetime_to_string.h index 14e8335388b2dc..4e30db19dc80fb 100644 --- a/be/src/vec/functions/function_date_or_datetime_to_string.h +++ b/be/src/vec/functions/function_date_or_datetime_to_string.h @@ -70,6 +70,10 @@ class FunctionDateOrDateTimeToString : public IFunction { RETURN_REAL_TYPE_FOR_DATEV2_FUNCTION(DataTypeString); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + bool is_variadic() const override { return true; } DataTypes get_variadic_argument_types_impl() const override { diff --git a/be/src/vec/functions/function_datetime_string_to_string.h b/be/src/vec/functions/function_datetime_string_to_string.h index 5dfa32e0c9fac3..bd69b85b2762a6 100644 --- a/be/src/vec/functions/function_datetime_string_to_string.h +++ b/be/src/vec/functions/function_datetime_string_to_string.h @@ -126,6 +126,10 @@ class FunctionDateTimeStringToString : public IFunction { return make_nullable(std::make_shared()); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + bool use_default_implementation_for_nulls() const override { return false; } ColumnNumbers get_arguments_that_are_always_constant() const override { return {1}; } diff --git a/be/src/vec/functions/function_fake.cpp b/be/src/vec/functions/function_fake.cpp index 646da600b50c13..10dc004a852162 100644 --- a/be/src/vec/functions/function_fake.cpp +++ b/be/src/vec/functions/function_fake.cpp @@ -42,6 +42,7 @@ namespace doris::vectorized { template struct FunctionFakeBaseImpl { + static bool has_return_type_in_signature() { return true; } static DataTypePtr get_return_type_impl(const DataTypes& arguments) { if constexpr (AlwaysNullable) { return make_nullable(std::make_shared()); @@ -62,6 +63,7 @@ struct FunctionFakeBaseImpl { }; struct FunctionExplode { + static bool has_return_type_in_signature() { return false; } static DataTypePtr get_return_type_impl(const DataTypes& arguments) { DCHECK(is_array(arguments[0])) << arguments[0]->get_name() << " not supported"; return make_nullable( @@ -73,6 +75,7 @@ struct FunctionExplode { // explode map: make map k,v as struct field struct FunctionExplodeMap { + static bool has_return_type_in_signature() { return false; } static DataTypePtr get_return_type_impl(const DataTypes& arguments) { DCHECK(is_map(arguments[0])) << arguments[0]->get_name() << " not supported"; DataTypes fieldTypes(2); @@ -86,6 +89,7 @@ struct FunctionExplodeMap { template struct FunctionPoseExplode { + static bool has_return_type_in_signature() { return false; } static DataTypePtr get_return_type_impl(const DataTypes& arguments) { DCHECK(is_array(arguments[0])) << arguments[0]->get_name() << " not supported"; DataTypes fieldTypes(2); @@ -105,6 +109,7 @@ struct FunctionPoseExplode { // explode json-object: expands json-object to struct with a pair of key and value in column string struct FunctionExplodeJsonObject { + static bool has_return_type_in_signature() { return false; } static DataTypePtr get_return_type_impl(const DataTypes& arguments) { DCHECK(WhichDataType(arguments[0]).is_json()) << " explode json object " << arguments[0]->get_name() << " not supported"; @@ -118,6 +123,7 @@ struct FunctionExplodeJsonObject { }; struct FunctionEsquery { + static bool has_return_type_in_signature() { return true; } static DataTypePtr get_return_type_impl(const DataTypes& arguments) { return FunctionFakeBaseImpl::get_return_type_impl(arguments); } diff --git a/be/src/vec/functions/function_fake.h b/be/src/vec/functions/function_fake.h index dabb5eb039afb7..2de3f9e4f8b498 100644 --- a/be/src/vec/functions/function_fake.h +++ b/be/src/vec/functions/function_fake.h @@ -38,6 +38,7 @@ class Block; namespace doris::vectorized { struct UDTFImpl { + static bool has_return_type_in_signature() { return true; } static DataTypePtr get_return_type_impl(const DataTypes& arguments) { return std::make_shared(); //just fake return uint8 } @@ -51,6 +52,10 @@ struct UDTFImpl { template class FunctionFake : public IFunction { public: + bool has_return_type_in_signature() const override { + return Impl::has_return_type_in_signature(); + } + static constexpr auto name = "fake"; static FunctionPtr create() { return std::make_shared(); } @@ -70,10 +75,7 @@ class FunctionFake : public IFunction { } bool use_default_implementation_for_nulls() const override { - if constexpr (std::is_same_v) { - return false; - } - return true; + return !static_cast(std::is_same_v); } bool use_default_implementation_for_constants() const override { return false; } diff --git a/be/src/vec/functions/function_grouping.h b/be/src/vec/functions/function_grouping.h index 0917b4d1db89ec..67abc6d7219d85 100644 --- a/be/src/vec/functions/function_grouping.h +++ b/be/src/vec/functions/function_grouping.h @@ -52,6 +52,10 @@ class FunctionGroupingBase : public IFunction { return std::make_shared(); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) const override { const ColumnWithTypeAndName& src_column = block.get_by_position(arguments[0]); diff --git a/be/src/vec/functions/function_ifnull.h b/be/src/vec/functions/function_ifnull.h index 9cd1ef5b36e0ca..bb92eaa9a70374 100644 --- a/be/src/vec/functions/function_ifnull.h +++ b/be/src/vec/functions/function_ifnull.h @@ -55,6 +55,8 @@ class FunctionIfNull : public IFunction { String get_name() const override { return name; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 2; } // be compatible with fe code diff --git a/be/src/vec/functions/function_json.cpp b/be/src/vec/functions/function_json.cpp index c53b31d7ec69f6..f6a3b3f3464b17 100644 --- a/be/src/vec/functions/function_json.cpp +++ b/be/src/vec/functions/function_json.cpp @@ -41,6 +41,7 @@ #include "common/compiler_util.h" // IWYU pragma: keep #include "common/status.h" #include "exprs/json_functions.h" +#include "vec/core/columns_with_type_and_name.h" #include "vec/io/io_helper.h" #ifdef __AVX2__ #include "util/jsonb_parser_simd.h" @@ -1396,11 +1397,11 @@ class FunctionJsonModifyImpl : public IFunction { bool use_default_implementation_for_nulls() const override { return false; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { bool is_nullable = false; // arguments: (json_str, path, val[, path, val...], type_flag) for (auto col = 0; col < arguments.size() - 1; col += 1) { - if (arguments[col]->is_nullable()) { + if (arguments[col].type->is_nullable()) { is_nullable = true; break; } @@ -1409,6 +1410,10 @@ class FunctionJsonModifyImpl : public IFunction { : std::make_shared(); } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(); + } + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) const override { auto result_column = ColumnString::create(); diff --git a/be/src/vec/functions/function_jsonb.cpp b/be/src/vec/functions/function_jsonb.cpp index dcae26f3c2f844..5b1b2efe86a5e3 100644 --- a/be/src/vec/functions/function_jsonb.cpp +++ b/be/src/vec/functions/function_jsonb.cpp @@ -33,6 +33,7 @@ #include "udf/udf.h" #include "util/jsonb_document.h" #include "util/jsonb_error.h" +#include "vec/core/columns_with_type_and_name.h" #ifdef __AVX2__ #include "util/jsonb_parser_simd.h" #else @@ -136,7 +137,7 @@ class FunctionJsonbParseBase : public IFunction { } } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { bool is_nullable = true; switch (nullable_mode) { case NullalbeMode::NULLABLE: @@ -146,7 +147,7 @@ class FunctionJsonbParseBase : public IFunction { is_nullable = false; break; case NullalbeMode::FOLLOW_INPUT: - is_nullable = arguments[0]->is_nullable(); + is_nullable = arguments[0].type->is_nullable(); break; } @@ -154,6 +155,10 @@ class FunctionJsonbParseBase : public IFunction { : std::make_shared(); } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(); + } + bool use_default_implementation_for_nulls() const override { return false; } Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { diff --git a/be/src/vec/functions/function_map.cpp b/be/src/vec/functions/function_map.cpp index 5b4e4202b20de8..0ad4116b797d3d 100644 --- a/be/src/vec/functions/function_map.cpp +++ b/be/src/vec/functions/function_map.cpp @@ -68,6 +68,8 @@ class FunctionMap : public IFunction { bool is_variadic() const override { return true; } + bool has_return_type_in_signature() const override { return false; } + bool use_default_implementation_for_nulls() const override { return false; } size_t get_number_of_arguments() const override { return 0; } @@ -140,6 +142,8 @@ class FunctionMapContains : public IFunction { bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 2; } bool use_default_implementation_for_nulls() const override { @@ -243,6 +247,8 @@ class FunctionMapEntries : public IFunction { bool is_variadic() const override { return false; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/function_multi_same_args.h b/be/src/vec/functions/function_multi_same_args.h index f22bae640aeda4..fd86246abfab12 100644 --- a/be/src/vec/functions/function_multi_same_args.h +++ b/be/src/vec/functions/function_multi_same_args.h @@ -36,6 +36,8 @@ class FunctionMultiSameArgs : public IFunction { bool use_default_implementation_for_nulls() const override { return true; } + bool has_return_type_in_signature() const override { return false; } + bool is_variadic() const override { return true; } size_t get_number_of_arguments() const override { return 0; } diff --git a/be/src/vec/functions/function_nullables.cpp b/be/src/vec/functions/function_nullables.cpp index b1e72ff52a71f4..bc3dbd6fe20f86 100644 --- a/be/src/vec/functions/function_nullables.cpp +++ b/be/src/vec/functions/function_nullables.cpp @@ -40,6 +40,8 @@ class FunctionNullable : public IFunction { static FunctionPtr create() { return std::make_shared(); } + bool has_return_type_in_signature() const override { return false; } + String get_name() const override { return name; } size_t get_number_of_arguments() const override { return 1; } @@ -74,6 +76,8 @@ class FunctionNonNullable : public IFunction { String get_name() const override { return name; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/function_reverse.h b/be/src/vec/functions/function_reverse.h index ee0005a305d8ce..be144e0ecb3125 100644 --- a/be/src/vec/functions/function_reverse.h +++ b/be/src/vec/functions/function_reverse.h @@ -29,6 +29,8 @@ class FunctionReverseCommon : public IFunction { String get_name() const override { return name; } + bool has_return_type_in_signature() const override { return false; } + size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/function_size.cpp b/be/src/vec/functions/function_size.cpp index 68c873c8ea6c4b..1feee37d2d9a2d 100644 --- a/be/src/vec/functions/function_size.cpp +++ b/be/src/vec/functions/function_size.cpp @@ -15,9 +15,13 @@ // specific language governing permissions and limitations // under the License. +#include + #include "simple_function_factory.h" +#include "vec/aggregate_functions/aggregate_function.h" #include "vec/columns/column_array.h" #include "vec/columns/column_map.h" +#include "vec/core/columns_with_type_and_name.h" #include "vec/data_types/data_type_array.h" #include "vec/data_types/data_type_number.h" #include "vec/functions/array/function_array_utils.h" @@ -35,8 +39,8 @@ class FunctionSize : public IFunction { bool is_variadic() const override { return true; } size_t get_number_of_arguments() const override { return 0; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - DataTypePtr datatype = arguments[0]; + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + DataTypePtr datatype = arguments[0].type; if (datatype->is_nullable()) { datatype = assert_cast(datatype.get())->get_nested_type(); } @@ -45,6 +49,10 @@ class FunctionSize : public IFunction { return std::make_shared(); } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(); + } + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) const override { const auto& [left_column, left_const] = diff --git a/be/src/vec/functions/function_string.h b/be/src/vec/functions/function_string.h index a729af5948a73f..6af30aeb6fe02f 100644 --- a/be/src/vec/functions/function_string.h +++ b/be/src/vec/functions/function_string.h @@ -63,6 +63,7 @@ #include "vec/core/block.h" #include "vec/core/column_numbers.h" #include "vec/core/column_with_type_and_name.h" +#include "vec/core/columns_with_type_and_name.h" #include "vec/core/types.h" #include "vec/data_types/data_type.h" #include "vec/utils/template_helpers.hpp" @@ -1324,14 +1325,19 @@ class FunctionStringConcatWs : public IFunction { size_t get_number_of_arguments() const override { return 0; } bool is_variadic() const override { return true; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - const IDataType* first_type = arguments[0].get(); + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + const IDataType* first_type = arguments[0].type.get(); if (first_type->is_nullable()) { return make_nullable(std::make_shared()); } else { return std::make_shared(); } } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(); + } + bool use_default_implementation_for_nulls() const override { return false; } Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, @@ -2110,14 +2116,19 @@ class FunctionSplitByString : public IFunction { size_t get_number_of_arguments() const override { return 2; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - DCHECK(is_string(arguments[0])) + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + DCHECK(arguments.size() == 2) << "function " << name << " should have 2 arguments"; + DCHECK(is_string(arguments[0].type)) << "first argument for function: " << name << " should be string" - << " and arguments[0] is " << arguments[0]->get_name(); - DCHECK(is_string(arguments[1])) + << " and arguments[0] is " << arguments[0].type->get_name(); + DCHECK(is_string(arguments[1].type)) << "second argument for function: " << name << " should be string" - << " and arguments[1] is " << arguments[1]->get_name(); - return std::make_shared(make_nullable(arguments[0])); + << " and arguments[1] is " << arguments[1].type->get_name(); + return std::make_shared(make_nullable(arguments[0].type)); + } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(std::make_shared()); } Status execute_impl(FunctionContext* /*context*/, Block& block, const ColumnNumbers& arguments, @@ -2387,13 +2398,18 @@ class FunctionCountSubString : public IFunction { size_t get_number_of_arguments() const override { return 2; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - DCHECK(is_string(arguments[0])) + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + DCHECK(arguments.size() == 2) << "function " << name << " should have 2 arguments"; + DCHECK(is_string(arguments[0].type)) << "first argument for function: " << name << " should be string" - << " and arguments[0] is " << arguments[0]->get_name(); - DCHECK(is_string(arguments[1])) + << " and arguments[0] is " << arguments[0].type->get_name(); + DCHECK(is_string(arguments[1].type)) << "second argument for function: " << name << " should be string" - << " and arguments[1] is " << arguments[1]->get_name(); + << " and arguments[1] is " << arguments[1].type->get_name(); + return std::make_shared(); + } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { return std::make_shared(); } diff --git a/be/src/vec/functions/function_string_to_string.h b/be/src/vec/functions/function_string_to_string.h index ea8c654faa1d31..acfed4d676eb93 100644 --- a/be/src/vec/functions/function_string_to_string.h +++ b/be/src/vec/functions/function_string_to_string.h @@ -20,8 +20,12 @@ #pragma once +#include + +#include "vec/aggregate_functions/aggregate_function.h" #include "vec/columns/column_string.h" #include "vec/columns/column_vector.h" +#include "vec/core/columns_with_type_and_name.h" #include "vec/data_types/data_type_number.h" #include "vec/data_types/data_type_string.h" #include "vec/functions/function.h" @@ -42,14 +46,18 @@ class FunctionStringToString : public IFunction { size_t get_number_of_arguments() const override { return 1; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - if (!is_string_or_fixed_string(arguments[0])) { + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + if (!is_string_or_fixed_string(arguments[0].type)) { throw doris::Exception(ErrorCode::INVALID_ARGUMENT, "Illegal type {} of argument of function {}", - arguments[0]->get_name(), get_name()); + arguments[0].type->get_name(), get_name()); } - return arguments[0]; + return arguments[0].type; + } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(); } DataTypes get_variadic_argument_types_impl() const override { diff --git a/be/src/vec/functions/function_struct.cpp b/be/src/vec/functions/function_struct.cpp index 49348f56f9036b..83bd62ee2ed4ed 100644 --- a/be/src/vec/functions/function_struct.cpp +++ b/be/src/vec/functions/function_struct.cpp @@ -59,6 +59,8 @@ class FunctionStruct : public IFunction { bool is_variadic() const override { return true; } + bool has_return_type_in_signature() const override { return false; } + bool use_default_implementation_for_nulls() const override { return false; } size_t get_number_of_arguments() const override { return 0; } diff --git a/be/src/vec/functions/function_struct_element.cpp b/be/src/vec/functions/function_struct_element.cpp index f547588dece646..a3d07107e11a77 100644 --- a/be/src/vec/functions/function_struct_element.cpp +++ b/be/src/vec/functions/function_struct_element.cpp @@ -51,6 +51,8 @@ class FunctionStructElement : public IFunction { size_t get_number_of_arguments() const override { return 2; } + bool has_return_type_in_signature() const override { return false; } + ColumnNumbers get_arguments_that_are_always_constant() const override { return {1}; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { diff --git a/be/src/vec/functions/function_time_value_to_field.cpp b/be/src/vec/functions/function_time_value_to_field.cpp index 8c8ec3cf9ab219..ce2431ab9cbc27 100644 --- a/be/src/vec/functions/function_time_value_to_field.cpp +++ b/be/src/vec/functions/function_time_value_to_field.cpp @@ -47,6 +47,10 @@ class FunctionTimeValueToField : public IFunction { return std::make_shared(); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + bool use_default_implementation_for_nulls() const override { return true; } Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp index cc812b8968124f..07586f7b91df29 100644 --- a/be/src/vec/functions/function_timestamp.cpp +++ b/be/src/vec/functions/function_timestamp.cpp @@ -249,7 +249,7 @@ struct MakeDateImpl { static DataTypes get_variadic_argument_types() { return {}; } static DataTypePtr get_return_type_impl(const DataTypes& arguments) { - return make_nullable(std::make_shared()); + return make_nullable(std::make_shared()); } static Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, @@ -498,7 +498,7 @@ class FromDays : public IFunction { size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - return make_nullable(std::make_shared()); + return make_nullable(std::make_shared()); } Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, @@ -572,6 +572,10 @@ struct UnixTimeStampImpl { return std::make_shared(); } + static DataTypePtr get_return_type_impl(const DataTypes& arguments) { + return std::make_shared(); + } + static Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) { @@ -607,6 +611,25 @@ struct UnixTimeStampDateImpl { } } + static DataTypePtr get_return_type_impl(const DataTypes& arguments) { + if constexpr (std::is_same_v) { + if (arguments[0]->is_nullable()) { + UInt32 scale = static_cast(arguments[0].get()) + ->get_nested_type() + ->get_scale(); + return make_nullable( + std::make_shared>(10 + scale, scale)); + } + UInt32 scale = arguments[0]->get_scale(); + return std::make_shared>(10 + scale, scale); + } else { + if (arguments[0]->is_nullable()) { + return make_nullable(std::make_shared()); + } + return std::make_shared(); + } + } + static Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) { @@ -687,6 +710,10 @@ struct UnixTimeStampStrImpl { return {std::make_shared(), std::make_shared()}; } + static DataTypePtr get_return_type_impl(const DataTypes& arguments) { + return make_nullable(std::make_shared>(16, 6)); + } + static DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) { return make_nullable(std::make_shared>(16, 6)); } @@ -758,6 +785,10 @@ class FunctionUnixTimestamp : public IFunction { return Impl::get_return_type_impl(arguments); } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return Impl::get_return_type_impl(arguments); + } + DataTypes get_variadic_argument_types_impl() const override { return Impl::get_variadic_argument_types(); } @@ -799,6 +830,10 @@ class DateTimeToTimestamp : public IFunction { return std::make_shared(); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) const override { const auto& arg_col = block.get_by_position(arguments[0]).column; @@ -855,6 +890,10 @@ class FunctionDateOrDateTimeToDate : public IFunction { } } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + DataTypes get_variadic_argument_types_impl() const override { return {std::make_shared()}; } diff --git a/be/src/vec/functions/function_tokenize.h b/be/src/vec/functions/function_tokenize.h index 4a7cb0dad26214..c034a70d702748 100644 --- a/be/src/vec/functions/function_tokenize.h +++ b/be/src/vec/functions/function_tokenize.h @@ -56,14 +56,18 @@ class FunctionTokenize : public IFunction { size_t get_number_of_arguments() const override { return 2; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - DCHECK(is_string(arguments[0])) + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + DCHECK(is_string(arguments[0].type)) << "first argument for function: " << name << " should be string" - << " and arguments[0] is " << arguments[0]->get_name(); - DCHECK(is_string(arguments[1])) + << " and arguments[0] is " << arguments[0].type->get_name(); + DCHECK(is_string(arguments[1].type)) << "second argument for function: " << name << " should be string" - << " and arguments[1] is " << arguments[1]->get_name(); - return std::make_shared(make_nullable(arguments[0])); + << " and arguments[1] is " << arguments[1].type->get_name(); + return std::make_shared(make_nullable(arguments[0].type)); + } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(std::make_shared()); } void _do_tokenize(const ColumnString& src_column_string, InvertedIndexCtx& inverted_index_ctx, IColumn& dest_nested_column, ColumnArray::Offsets64& dest_offsets, diff --git a/be/src/vec/functions/function_unary_arithmetic.h b/be/src/vec/functions/function_unary_arithmetic.h index 54d03f602593e1..be4e402c57498e 100644 --- a/be/src/vec/functions/function_unary_arithmetic.h +++ b/be/src/vec/functions/function_unary_arithmetic.h @@ -81,6 +81,8 @@ class FunctionUnaryArithmetic : public IFunction { size_t get_number_of_arguments() const override { return 1; } + bool has_return_type_in_signature() const override { return false; } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DataTypePtr result; bool valid = cast_type(arguments[0].get(), [&](const auto& type) { diff --git a/be/src/vec/functions/function_utility.cpp b/be/src/vec/functions/function_utility.cpp index 40dd11677758de..af2b7e114faac7 100644 --- a/be/src/vec/functions/function_utility.cpp +++ b/be/src/vec/functions/function_utility.cpp @@ -61,13 +61,17 @@ class FunctionSleep : public IFunction { size_t get_number_of_arguments() const override { return 1; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - if (arguments[0]->is_nullable()) { + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + if (arguments[0].type->is_nullable()) { return make_nullable(std::make_shared()); } return std::make_shared(); } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(); + } + bool use_default_implementation_for_nulls() const override { return false; } // Sleep function should not be executed during open stage, this will makes fragment prepare @@ -132,6 +136,10 @@ class FunctionVersion : public IFunction { return std::make_shared(); } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) const override { auto res_column = ColumnString::create(); diff --git a/be/src/vec/functions/function_variadic_arguments.h b/be/src/vec/functions/function_variadic_arguments.h index 530b204e8067a1..68e924dd852124 100644 --- a/be/src/vec/functions/function_variadic_arguments.h +++ b/be/src/vec/functions/function_variadic_arguments.h @@ -54,6 +54,10 @@ class FunctionVariadicArgumentsBase : public IFunction { return res; } + DataTypePtr get_return_type_impl(const DataTypes& types) const override { + return std::make_shared(); + } + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, uint32_t result, size_t input_rows_count) const override { ToDataType to_type; diff --git a/be/src/vec/functions/function_variant_element.cpp b/be/src/vec/functions/function_variant_element.cpp index 9d0aab7685424e..671ddaf4ef9894 100644 --- a/be/src/vec/functions/function_variant_element.cpp +++ b/be/src/vec/functions/function_variant_element.cpp @@ -37,6 +37,7 @@ #include "vec/common/assert_cast.h" #include "vec/common/string_ref.h" #include "vec/core/block.h" +#include "vec/core/columns_with_type_and_name.h" #include "vec/data_types/data_type.h" #include "vec/data_types/data_type_nothing.h" #include "vec/data_types/data_type_nullable.h" @@ -67,16 +68,21 @@ class FunctionVariantElement : public IFunction { return {std::make_shared(), std::make_shared()}; } - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - DCHECK((WhichDataType(remove_nullable(arguments[0]))).is_variant_type()) + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + DCHECK((WhichDataType(remove_nullable(arguments[0].type))).is_variant_type()) << "First argument for function: " << name - << " should be DataTypeObject but it has type " << arguments[0]->get_name() << "."; - DCHECK(is_string(arguments[1])) + << " should be DataTypeObject but it has type " << arguments[0].type->get_name() + << "."; + DCHECK(is_string(arguments[1].type)) << "Second argument for function: " << name << " should be String but it has type " - << arguments[1]->get_name() << "."; + << arguments[1].type->get_name() << "."; return make_nullable(std::make_shared()); } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared(); + } + // wrap variant column with nullable // 1. if variant is null root(empty or nothing as root), then nullable map is all null // 2. if variant is scalar variant, then use the root's nullable map diff --git a/be/src/vec/functions/functions_logical.cpp b/be/src/vec/functions/functions_logical.cpp index f99f0447725edd..f2fff7084a445b 100644 --- a/be/src/vec/functions/functions_logical.cpp +++ b/be/src/vec/functions/functions_logical.cpp @@ -171,13 +171,6 @@ void null_execute_impl(ColumnRawPtrs arguments, ColumnWithTypeAndName& result_in template DataTypePtr FunctionAnyArityLogical::get_return_type_impl( const DataTypes& arguments) const { - if (arguments.size() < 2) { - throw doris::Exception( - ErrorCode::INVALID_ARGUMENT, - "Number of arguments for function \"{}\" should be at least 2: passed {}", - get_name(), arguments.size()); - } - bool has_nullable_arguments = false; for (size_t i = 0; i < arguments.size(); ++i) { const auto& arg_type = arguments[i]; @@ -241,7 +234,7 @@ struct UnaryOperationImpl { template