From e10b31f0d7591878eafdd05d787533259030ab23 Mon Sep 17 00:00:00 2001 From: koarz <3577087577@qq.com> Date: Mon, 2 Dec 2024 18:04:23 +0800 Subject: [PATCH 01/33] remove --- be/src/vec/functions/function.cpp | 35 +------------------------------ 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/be/src/vec/functions/function.cpp b/be/src/vec/functions/function.cpp index 851e430d2f0407..75bb41de74de0a 100644 --- a/be/src/vec/functions/function.cpp +++ b/be/src/vec/functions/function.cpp @@ -296,40 +296,7 @@ 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() + return (is_decimal(return_type->is_nullable() ? ((DataTypeNullable*)return_type.get())->get_nested_type() : return_type) && is_decimal(func_return_type->is_nullable() From 9c5f654fcb09d9f77d8d897a86a9d386da701e2a Mon Sep 17 00:00:00 2001 From: koarz <3577087577@qq.com> Date: Tue, 3 Dec 2024 13:37:12 +0800 Subject: [PATCH 02/33] fix --- conf/be.conf | 4 ++++ conf/fe.conf | 4 ++++ .../nereids/trees/expressions/functions/scalar/Date.java | 4 ++-- gensrc/script/doris_builtins_functions.py | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/conf/be.conf b/conf/be.conf index 5ad5e07176d545..6471a3ae6cf6b7 100644 --- a/conf/be.conf +++ b/conf/be.conf @@ -15,6 +15,10 @@ # specific language governing permissions and limitations # under the License. +JAVA_HOME=/home/koarz/tools/jdk-17.0.10 + +priority_networks=192.168.19.42/24 + CUR_DATE=`date +%Y%m%d-%H%M%S` # Log dir diff --git a/conf/fe.conf b/conf/fe.conf index 72734a86733a31..61cd3a1c8f8422 100644 --- a/conf/fe.conf +++ b/conf/fe.conf @@ -21,6 +21,10 @@ ## see fe/src/org/apache/doris/common/Config.java ##################################################################### +JAVA_HOME=/home/koarz/tools/jdk-17.0.10 + +priority_networks=192.168.19.42/24 + CUR_DATE=`date +%Y%m%d-%H%M%S` # Log dir diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Date.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Date.java index 80c6178cd3ffb8..c8a1fe3d48f00a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Date.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Date.java @@ -19,9 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; -import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.Monotonic; +import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -39,7 +39,7 @@ * ScalarFunction 'date'. This class is generated by GenerateFunction. */ public class Date extends ScalarFunction - implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, Monotonic { + implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, PropagateNullLiteral, Monotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateV2Type.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT), diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py index 31b02f9b97980e..849dda5390a353 100644 --- a/gensrc/script/doris_builtins_functions.py +++ b/gensrc/script/doris_builtins_functions.py @@ -1153,7 +1153,7 @@ [['str_to_date'], 'DATETIMEV2', ['STRING', 'STRING'], 'ALWAYS_NULLABLE'], [['date_format'], 'VARCHAR', ['DATETIMEV2', 'VARCHAR'], 'ALWAYS_NULLABLE'], [['date_format'], 'VARCHAR', ['DATEV2', 'VARCHAR'], 'ALWAYS_NULLABLE'], - [['date', 'to_date', 'datev2', 'to_datev2'], 'DATEV2', ['DATETIMEV2'], 'ALWAYS_NULLABLE'], + [['date', 'to_date', 'datev2', 'to_datev2'], 'DATEV2', ['DATETIMEV2'], ''], [['dayname'], 'VARCHAR', ['DATETIMEV2'], ''], [['monthname'], 'VARCHAR', ['DATETIMEV2'], ''], From e1bd5d286c7f98a70c6c14850b24f0553ec3f83a Mon Sep 17 00:00:00 2001 From: koarz <3577087577@qq.com> Date: Tue, 3 Dec 2024 16:18:06 +0800 Subject: [PATCH 03/33] fix --- conf/be.conf | 4 ---- conf/fe.conf | 2 +- .../nereids/trees/expressions/functions/scalar/Date.java | 5 +++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/conf/be.conf b/conf/be.conf index 6471a3ae6cf6b7..5ad5e07176d545 100644 --- a/conf/be.conf +++ b/conf/be.conf @@ -15,10 +15,6 @@ # specific language governing permissions and limitations # under the License. -JAVA_HOME=/home/koarz/tools/jdk-17.0.10 - -priority_networks=192.168.19.42/24 - CUR_DATE=`date +%Y%m%d-%H%M%S` # Log dir diff --git a/conf/fe.conf b/conf/fe.conf index 61cd3a1c8f8422..a9553b941817bd 100644 --- a/conf/fe.conf +++ b/conf/fe.conf @@ -53,7 +53,7 @@ JAVA_OPTS_FOR_JDK_17="-Dfile.encoding=UTF-8 -Djavax.security.auth.useSubjectCred http_port = 8030 rpc_port = 9020 query_port = 9030 -edit_log_port = 9010 +edit_log_port = 9011 arrow_flight_sql_port = -1 # Choose one if there are more than one ip except loopback address. diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Date.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Date.java index c8a1fe3d48f00a..40c2932279d056 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Date.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Date.java @@ -21,8 +21,8 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.Monotonic; -import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; +import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -39,7 +39,8 @@ * ScalarFunction 'date'. This class is generated by GenerateFunction. */ public class Date extends ScalarFunction - implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, PropagateNullLiteral, Monotonic { + implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + PropagateNullLiteral, Monotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateV2Type.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT), From 08b83eeb424fca606b29e146928caefdfe29e0b2 Mon Sep 17 00:00:00 2001 From: koarz <3577087577@qq.com> Date: Tue, 3 Dec 2024 16:23:08 +0800 Subject: [PATCH 04/33] fix --- conf/fe.conf | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/conf/fe.conf b/conf/fe.conf index a9553b941817bd..72734a86733a31 100644 --- a/conf/fe.conf +++ b/conf/fe.conf @@ -21,10 +21,6 @@ ## see fe/src/org/apache/doris/common/Config.java ##################################################################### -JAVA_HOME=/home/koarz/tools/jdk-17.0.10 - -priority_networks=192.168.19.42/24 - CUR_DATE=`date +%Y%m%d-%H%M%S` # Log dir @@ -53,7 +49,7 @@ JAVA_OPTS_FOR_JDK_17="-Dfile.encoding=UTF-8 -Djavax.security.auth.useSubjectCred http_port = 8030 rpc_port = 9020 query_port = 9030 -edit_log_port = 9011 +edit_log_port = 9010 arrow_flight_sql_port = -1 # Choose one if there are more than one ip except loopback address. From 0de607b1772e1700e334f2750abd21b654a01d17 Mon Sep 17 00:00:00 2001 From: koarz <3577087577@qq.com> Date: Thu, 5 Dec 2024 19:15:54 +0800 Subject: [PATCH 05/33] fix --- .../functions/array/function_array_apply.cpp | 2 + .../functions/array/function_array_binary.h | 2 + .../functions/array/function_array_compact.h | 2 + .../functions/array/function_array_concat.cpp | 1 + .../array/function_array_constructor.cpp | 2 + .../array/function_array_contains_all.cpp | 20 ++++++--- .../array/function_array_cum_sum.cpp | 2 + .../array/function_array_difference.h | 2 + .../functions/array/function_array_distinct.h | 2 + .../functions/array/function_array_element.h | 2 + .../array/function_array_enumerate.cpp | 2 + .../array/function_array_enumerate_uniq.cpp | 1 + .../functions/array/function_array_exists.cpp | 2 + .../functions/array/function_array_filter.cpp | 1 + .../functions/array/function_array_index.h | 9 +++- .../vec/functions/array/function_array_join.h | 8 ++++ .../functions/array/function_array_mapped.h | 2 + .../vec/functions/array/function_array_nary.h | 2 + .../functions/array/function_array_pop.cpp | 1 + .../array/function_array_pushback.cpp | 1 + .../array/function_array_pushfront.cpp | 1 + .../functions/array/function_array_remove.h | 2 + .../array/function_array_shuffle.cpp | 2 + .../functions/array/function_array_slice.h | 2 + .../vec/functions/array/function_array_sort.h | 2 + .../functions/array/function_array_sortby.cpp | 2 + .../functions/array/function_array_split.cpp | 1 + .../array/function_array_with_constant.cpp | 1 + .../functions/array/function_array_zip.cpp | 1 + .../functions/array/function_arrays_overlap.h | 19 +++++--- be/src/vec/functions/function.h | 9 ++++ .../functions/function_binary_arithmetic.h | 15 ++++--- be/src/vec/functions/function_case.h | 1 + be/src/vec/functions/function_cast.h | 22 +++++----- be/src/vec/functions/function_coalesce.cpp | 2 + .../function_date_or_datetime_computation.h | 15 +++++-- .../function_date_or_datetime_to_something.h | 5 +++ .../function_date_or_datetime_to_string.h | 4 ++ .../function_datetime_string_to_string.h | 4 ++ be/src/vec/functions/function_fake.h | 2 + be/src/vec/functions/function_grouping.h | 4 ++ be/src/vec/functions/function_ifnull.h | 2 + be/src/vec/functions/function_json.cpp | 9 +++- be/src/vec/functions/function_jsonb.cpp | 21 +++++---- be/src/vec/functions/function_map.cpp | 6 +++ .../vec/functions/function_multi_same_args.h | 2 + be/src/vec/functions/function_nullables.cpp | 4 ++ be/src/vec/functions/function_reverse.h | 2 + be/src/vec/functions/function_size.cpp | 12 +++++- be/src/vec/functions/function_string.h | 43 +++++++++++++------ .../vec/functions/function_string_to_string.h | 16 +++++-- be/src/vec/functions/function_struct.cpp | 2 + .../vec/functions/function_struct_element.cpp | 2 + .../function_time_value_to_field.cpp | 4 ++ be/src/vec/functions/function_timestamp.cpp | 39 +++++++++++++++++ be/src/vec/functions/function_tokenize.h | 16 ++++--- .../vec/functions/function_unary_arithmetic.h | 2 + be/src/vec/functions/function_utility.cpp | 12 +++++- .../functions/function_variadic_arguments.h | 4 ++ .../functions/function_variant_element.cpp | 16 ++++--- be/src/vec/functions/functions_logical.cpp | 9 +--- be/src/vec/functions/if.cpp | 2 + be/src/vec/functions/nullif.cpp | 2 + .../vec/functions/simple_function_factory.h | 10 +++++ .../expressions/functions/scalar/DateV2.java | 22 +++++++++- 65 files changed, 353 insertions(+), 88 deletions(-) diff --git a/be/src/vec/functions/array/function_array_apply.cpp b/be/src/vec/functions/array/function_array_apply.cpp index 75425389dd975c..36bee43f031707 100644 --- a/be/src/vec/functions/array/function_array_apply.cpp +++ b/be/src/vec/functions/array/function_array_apply.cpp @@ -64,6 +64,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 return_type_depend_on_argument_type() override { return true; } + 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..a7d317805bcd74 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 return_type_depend_on_argument_type() override { return true; } + 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..53d88fd0bb4bd6 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 return_type_depend_on_argument_type() override { return true; } + 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..a1ab8661a4a060 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 return_type_depend_on_argument_type() override { return true; } 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..df54c147237690 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 return_type_depend_on_argument_type() override { return true; } + 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 2f93a2a83b1a89..fd5b8a1888e877 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 return_type_depend_on_argument_type() override { return true; } + 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..417092239627ac 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 return_type_depend_on_argument_type() override { return true; } + 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 4b7e3e6f035d48..3c79f6822c661f 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 return_type_depend_on_argument_type() override { return true; } + 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..e3e6bd1ebd309d 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 return_type_depend_on_argument_type() override { return true; } + 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 0e8bca3e5cd3b1..4a5640b33fe94b 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 return_type_depend_on_argument_type() override { return true; } 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 21d6ab40007b6e..2cd17fe29bfbb4 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 return_type_depend_on_argument_type() override { return true; } 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..903d25d6156d21 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 return_type_depend_on_argument_type() override { return true; } + 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..536258ba361b7d 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 return_type_depend_on_argument_type() override { return true; } 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 957b2288fb746a..4944325970eca2 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..a23f93b3fd1bf1 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 return_type_depend_on_argument_type() override { return true; } + 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..84dd977d7590c6 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 return_type_depend_on_argument_type() override { return true; } + 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 2182699e0205b5..041a076cbfa215 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 return_type_depend_on_argument_type() override { return true; } 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..6ea4f765db8e79 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 return_type_depend_on_argument_type() override { return true; } 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..c51da38e236ea4 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 return_type_depend_on_argument_type() override { return true; } 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 197b032b0f8a4b..fdb0a853fffbe5 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 return_type_depend_on_argument_type() override { return true; } + 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 fbf5bcfcdf1686..91ff66f7606c92 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 return_type_depend_on_argument_type() override { return true; } + 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 2acd1d3fbe1fd4..97d2f341624df0 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 return_type_depend_on_argument_type() override { return true; } + 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..6408b73b696ed0 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 return_type_depend_on_argument_type() override { return true; } + 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 899bb40fba1423..2f131cf4240943 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 return_type_depend_on_argument_type() override { return true; } + 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..28f4bd8fba2e3f 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 return_type_depend_on_argument_type() override { return true; } 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..0215551c0fe684 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 return_type_depend_on_argument_type() override { return true; } // 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..78219c753521b9 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 return_type_depend_on_argument_type() override { return true; } /// 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 dd993100885e3a..c549741c27668d 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.h b/be/src/vec/functions/function.h index 92282c483948e6..82b43e57f196fb 100644 --- a/be/src/vec/functions/function.h +++ b/be/src/vec/functions/function.h @@ -299,6 +299,10 @@ class FunctionBuilderImpl : public IFunctionBuilder { ColumnNumbers get_arguments_that_are_always_constant() const override { return {}; } + // if a function's get_variadic_argument_types() not override and get_return_type_impl() + // result is not compile time be sure, the function should override return true + virtual bool return_type_depend_on_argument_type() { return false; } + 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,6 +346,8 @@ 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; @@ -532,6 +538,9 @@ class DefaultFunctionBuilder : public FunctionBuilderImpl { String get_name() const override { return function->get_name(); } bool is_variadic() const override { return function->is_variadic(); } + bool return_type_depend_on_argument_type() override { + return function->return_type_depend_on_argument_type(); + } 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 4c0b8e7a0890dc..81f167a82650f3 100644 --- a/be/src/vec/functions/function_binary_arithmetic.h +++ b/be/src/vec/functions/function_binary_arithmetic.h @@ -974,6 +974,8 @@ class FunctionBinaryArithmetic : public IFunction { size_t get_number_of_arguments() const override { return 2; } + bool return_type_depend_on_argument_type() override { return true; } + DataTypes get_variadic_argument_types_impl() const override { if constexpr (OpTraits::has_variadic_argument) { return OpTraits::Op::get_variadic_argument_types(); @@ -1057,13 +1059,12 @@ class FunctionBinaryArithmetic : public IFunction { using ResultDataType = typename BinaryOperationTraits::ResultDataType; - if constexpr ( - !std::is_same_v && - (IsDataTypeDecimal == - IsDataTypeDecimal< - ResultDataType>)&&(IsDataTypeDecimal == - (IsDataTypeDecimal || - IsDataTypeDecimal))) { + if constexpr (!std::is_same_v && + (IsDataTypeDecimal == + IsDataTypeDecimal) && + (IsDataTypeDecimal == + (IsDataTypeDecimal || + IsDataTypeDecimal))) { if (check_overflow_for_decimal) { // !is_to_null_type: plus, minus, multiply, // pow, bitxor, bitor, bitand diff --git a/be/src/vec/functions/function_case.h b/be/src/vec/functions/function_case.h index af44ea0d9b1ace..4d3769568ef359 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 return_type_depend_on_argument_type() override { return true; } 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 3ad456d60d201f..435982c6ac2213 100644 --- a/be/src/vec/functions/function_cast.h +++ b/be/src/vec/functions/function_cast.h @@ -453,8 +453,8 @@ struct ConvertImpl { block.get_by_position(result).column = ColumnNullable::create(std::move(col_to), std::move(col_null_map_to)); return Status::OK(); - } else if constexpr ((std::is_same_v)&&( - std::is_same_v)) { + } else if constexpr ((std::is_same_v) && + (std::is_same_v)) { for (size_t i = 0; i < size; ++i) { map_ipv4_to_ipv6(vec_from[i], reinterpret_cast(&vec_to[i])); } @@ -1140,7 +1140,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(); } @@ -1465,7 +1465,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(); @@ -1511,7 +1511,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(); } @@ -1582,11 +1582,11 @@ class FunctionCast final : public IFunctionBase { /// that will not throw an exception but return NULL in case of malformed input. function = FunctionConvertFromString::create(); } else if (requested_result_is_nullable && - (IsTimeType || IsTimeV2Type)&&!( - check_and_get_data_type(from_type.get()) || - check_and_get_data_type(from_type.get()) || - check_and_get_data_type(from_type.get()) || - check_and_get_data_type(from_type.get()))) { + (IsTimeType || IsTimeV2Type) && + !(check_and_get_data_type(from_type.get()) || + check_and_get_data_type(from_type.get()) || + check_and_get_data_type(from_type.get()) || + check_and_get_data_type(from_type.get()))) { function = FunctionConvertToTimeType::create(); } else { function = FunctionTo::Type::create(); @@ -2362,6 +2362,8 @@ class FunctionBuilderCast : public FunctionBuilderImpl { ColumnNumbers get_arguments_that_are_always_constant() const override { return {1}; } + bool return_type_depend_on_argument_type() override { return true; } + protected: FunctionBasePtr build_impl(const ColumnsWithTypeAndName& arguments, const DataTypePtr& return_type) const override { diff --git a/be/src/vec/functions/function_coalesce.cpp b/be/src/vec/functions/function_coalesce.cpp index 6e5db15d160c06..ee0999a2f4f791 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 return_type_depend_on_argument_type() override { return true; } + 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.h b/be/src/vec/functions/function_date_or_datetime_computation.h index 330ea75cba96c8..86b922cfa27681 100644 --- a/be/src/vec/functions/function_date_or_datetime_computation.h +++ b/be/src/vec/functions/function_date_or_datetime_computation.h @@ -746,6 +746,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; @@ -815,6 +819,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 { @@ -1067,6 +1075,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, @@ -1161,9 +1173,6 @@ class CurrentDateFunctionBuilder : public FunctionBuilderImpl { 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()); - } bool use_default_implementation_for_nulls() const override { return false; } 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.h b/be/src/vec/functions/function_fake.h index dabb5eb039afb7..7455fb5c6392c0 100644 --- a/be/src/vec/functions/function_fake.h +++ b/be/src/vec/functions/function_fake.h @@ -51,6 +51,8 @@ struct UDTFImpl { template class FunctionFake : public IFunction { public: + bool return_type_depend_on_argument_type() override { return true; } + static constexpr auto name = "fake"; static FunctionPtr create() { return std::make_shared(); } 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..7e16c96d856415 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 return_type_depend_on_argument_type() override { return true; } + 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 0e78eb894b20c5..91e011796cc94c 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 { @@ -951,7 +956,7 @@ struct JsonbExtractStringImpl { inner_loop_impl(i, res_data, res_offsets, null_map, writer, formater, l_raw, l_size, path); } //for - } //function + } //function static void vector_scalar(FunctionContext* context, const ColumnString::Chars& ldata, const ColumnString::Offsets& loffsets, const StringRef& rdata, ColumnString::Chars& res_data, ColumnString::Offsets& res_offsets, @@ -979,7 +984,7 @@ struct JsonbExtractStringImpl { inner_loop_impl(i, res_data, res_offsets, null_map, writer, formater, l_raw, l_size, path); } //for - } //function + } //function static void scalar_vector(FunctionContext* context, const StringRef& ldata, const ColumnString::Chars& rdata, const ColumnString::Offsets& roffsets, ColumnString::Chars& res_data, @@ -1009,7 +1014,7 @@ struct JsonbExtractStringImpl { inner_loop_impl(i, res_data, res_offsets, null_map, writer, formater, ldata.data, ldata.size, path); } //for - } //function + } //function }; template @@ -1137,7 +1142,7 @@ struct JsonbExtractImpl { inner_loop_impl(i, res, null_map, l_raw_str, l_str_size, path); } //for - } //function + } //function static void scalar_vector(FunctionContext* context, const StringRef& ldata, const ColumnString::Chars& rdata, const ColumnString::Offsets& roffsets, Container& res, @@ -1162,7 +1167,7 @@ struct JsonbExtractImpl { inner_loop_impl(i, res, null_map, ldata.data, ldata.size, path); } //for - } //function + } //function static void vector_scalar(FunctionContext* context, const ColumnString::Chars& ldata, const ColumnString::Offsets& loffsets, const StringRef& rdata, Container& res, NullMap& null_map, bool& is_invalid_json_path) { @@ -1185,7 +1190,7 @@ struct JsonbExtractImpl { inner_loop_impl(i, res, null_map, l_raw_str, l_str_size, path); } //for - } //function + } //function }; struct JsonbTypeExists { diff --git a/be/src/vec/functions/function_map.cpp b/be/src/vec/functions/function_map.cpp index 5b4e4202b20de8..624cb7abb5886a 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 return_type_depend_on_argument_type() override { return true; } + 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 return_type_depend_on_argument_type() override { return true; } + 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 return_type_depend_on_argument_type() override { return true; } + 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..4576d76b9d7bf7 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 return_type_depend_on_argument_type() override { return true; } + 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 91bce24f48fc8b..132cc9fdfe8b77 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 return_type_depend_on_argument_type() override { return true; } + String get_name() const override { return name; } size_t get_number_of_arguments() const override { return 1; } @@ -73,6 +75,8 @@ class FunctionNonNullable : public IFunction { String get_name() const override { return name; } + bool return_type_depend_on_argument_type() override { return true; } + 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..d724d694ab029c 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 return_type_depend_on_argument_type() override { return true; } + 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 6e4a18fdd3100e..ea97c1f68b8682 100644 --- a/be/src/vec/functions/function_string.h +++ b/be/src/vec/functions/function_string.h @@ -17,6 +17,7 @@ #pragma once +#include #include #include @@ -63,6 +64,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" @@ -1322,14 +1324,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, @@ -2105,14 +2112,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, @@ -2382,13 +2394,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..e76f5ea1b2800c 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 return_type_depend_on_argument_type() override { return true; } + 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..59e96536e2cb4b 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 return_type_depend_on_argument_type() override { return true; } + 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..22df81ef2d16dc 100644 --- a/be/src/vec/functions/function_timestamp.cpp +++ b/be/src/vec/functions/function_timestamp.cpp @@ -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..49932f62a5bb23 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 return_type_depend_on_argument_type() override { return true; } + 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 e04ff54dbe9d7c..ecc3ae95140487 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 0f474851f032ee..b3affc8315b664 100644 --- a/be/src/vec/functions/functions_logical.cpp +++ b/be/src/vec/functions/functions_logical.cpp @@ -170,13 +170,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]; @@ -240,7 +233,7 @@ struct UnaryOperationImpl { template