From b3806762a955c6144839fda1fd3acd25a2a193ef Mon Sep 17 00:00:00 2001 From: zhangstar333 <2561612514@qq.com> Date: Tue, 12 Dec 2023 11:00:27 +0800 Subject: [PATCH] array_zip and repeat --- .../functions/array/function_array_zip.cpp | 32 +++++++++++++++---- .../expressions/functions/scalar/Repeat.java | 2 -- gensrc/script/doris_builtins_functions.py | 1 - 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/be/src/vec/functions/array/function_array_zip.cpp b/be/src/vec/functions/array/function_array_zip.cpp index 2f9b94454e1f5e9..9b5cf35f427d22d 100644 --- a/be/src/vec/functions/array/function_array_zip.cpp +++ b/be/src/vec/functions/array/function_array_zip.cpp @@ -94,12 +94,16 @@ class FunctionArrayZip : public IFunction { size_t result, size_t input_rows_count) const override { size_t num_element = arguments.size(); - // all the columns must have the same size as the first column + // all the columns must have the same size as the first column, except have NULL literal ColumnPtr first_array_column; Columns tuple_columns(num_element); + bool have_null_literal = false; + int nested_column_data_num = 0; for (size_t i = 0; i < num_element; ++i) { auto col = block.get_by_position(arguments[i]).column; + auto type = block.get_by_position(arguments[i]).type; + const auto& nested_type = assert_cast(*type).get_nested_type(); col = col->convert_to_full_column_if_const(); const auto* column_array = check_and_get_column(col.get()); @@ -108,23 +112,39 @@ class FunctionArrayZip : public IFunction { "execute failed, function {}'s {}-th argument should be array bet get {}", get_name(), i + 1, block.get_by_position(arguments[i]).type->get_name())); } + bool is_null_literal = nested_type->is_null_literal(); + have_null_literal |= is_null_literal; if (i == 0) { first_array_column = col; - } else if (!column_array->has_equal_offsets( + } else if (!have_null_literal && + !column_array->has_equal_offsets( static_cast(*first_array_column))) { return Status::RuntimeError( fmt::format("execute failed, function {}'s {}-th argument should have same " "offsets with first argument", get_name(), i + 1)); } - - tuple_columns[i] = column_array->get_data_ptr(); + if (is_null_literal) { //wants handle: select /*set_var(enable_fold_constant_by_be = true) */ array_zip([1, 2, 3], null, ['foo', 'bar', 'test']); + auto nullable_column = + ColumnNullable::create(ColumnUInt8::create(nested_column_data_num, 1), + ColumnUInt8::create(nested_column_data_num, 1)); + tuple_columns[i] = std::move(nullable_column); + } else { + tuple_columns[i] = column_array->get_data_ptr(); + nested_column_data_num = column_array->get_data_ptr()->size(); + } } auto tuples = ColumnStruct::create(tuple_columns); - auto nullable_tuples = - ColumnNullable::create(tuples, ColumnUInt8::create(tuples->size(), 0)); + + ColumnPtr null_map = nullptr; + if (have_null_literal) { + null_map = ColumnUInt8::create(tuples->size(), 1); + } else { + null_map = ColumnUInt8::create(tuples->size(), 0); + } + auto nullable_tuples = ColumnNullable::create(tuples, null_map); auto res_column = ColumnArray::create( nullable_tuples, static_cast(*first_array_column).get_offsets_ptr()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Repeat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Repeat.java index 5ed3b20ddb465b2..b85a812197f55bb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Repeat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Repeat.java @@ -25,7 +25,6 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.IntegerType; import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.VarcharType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -39,7 +38,6 @@ public class Repeat extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT, IntegerType.INSTANCE), FunctionSignature.ret(StringType.INSTANCE).args(StringType.INSTANCE, IntegerType.INSTANCE) ); diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py index d7eff94f803fa18..ead0c4c095b3d4a 100644 --- a/gensrc/script/doris_builtins_functions.py +++ b/gensrc/script/doris_builtins_functions.py @@ -1558,7 +1558,6 @@ [['null_or_empty'], 'BOOLEAN', ['VARCHAR'], 'ALWAYS_NOT_NULLABLE'], [['not_null_or_empty'], 'BOOLEAN', ['VARCHAR'], 'ALWAYS_NOT_NULLABLE'], [['space'], 'VARCHAR', ['INT'], ''], - [['repeat'], 'VARCHAR', ['VARCHAR', 'INT'], 'ALWAYS_NULLABLE'], [['lpad'], 'VARCHAR', ['VARCHAR', 'INT', 'VARCHAR'], 'ALWAYS_NULLABLE'], [['rpad'], 'VARCHAR', ['VARCHAR', 'INT', 'VARCHAR'], 'ALWAYS_NULLABLE'], [['append_trailing_char_if_absent'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], 'ALWAYS_NULLABLE'],