diff --git a/be/src/vec/functions/array/function_array_enumerate.cpp b/be/src/vec/functions/array/function_array_enumerate.cpp index dd0bcfc7bc3aed..1b8197ac96f6a2 100644 --- a/be/src/vec/functions/array/function_array_enumerate.cpp +++ b/be/src/vec/functions/array/function_array_enumerate.cpp @@ -56,7 +56,7 @@ class FunctionArrayEnumerate : public IFunction { static constexpr auto name = "array_enumerate"; static FunctionPtr create() { return std::make_shared(); } String get_name() const override { return name; } - bool use_default_implementation_for_nulls() const override { return false; } + bool use_default_implementation_for_nulls() const override { return true; } size_t get_number_of_arguments() const override { return 1; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { const DataTypeArray* array_type = 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 e4f4c94623a0d8..3e2c6a2400d89b 100644 --- a/be/src/vec/functions/array/function_array_enumerate_uniq.cpp +++ b/be/src/vec/functions/array/function_array_enumerate_uniq.cpp @@ -76,7 +76,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 use_default_implementation_for_nulls() const override { return false; } + bool use_default_implementation_for_nulls() const override { return true; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { if (arguments.empty()) { @@ -95,15 +95,13 @@ class FunctionArrayEnumerateUniq : public IFunction { "The {} -th argument for function: {} .must be an array but it type is {}", i, get_name(), arguments[i]->get_name()); } - if (i == 0) { - is_nested_nullable = array_type->get_nested_type()->is_nullable(); - } + is_nested_nullable = is_nested_nullable | array_type->get_nested_type()->is_nullable(); } auto return_nested_type = std::make_shared(); DataTypePtr return_type = std::make_shared( is_nested_nullable ? make_nullable(return_nested_type) : return_nested_type); - if (arguments.size() == 1 && arguments[0]->is_nullable()) { + if (arguments[0]->is_nullable()) { return_type = make_nullable(return_type); } return return_type; @@ -147,7 +145,7 @@ class FunctionArrayEnumerateUniq : public IFunction { src_offsets = array->get_offsets_ptr(); } else if (*offsets != cur_offsets) { return Status::RuntimeError(fmt::format( - "lengths of all arrays of fucntion {} must be equal.", get_name())); + "lengths of all arrays of function {} must be equal.", get_name())); } const auto* array_data = &array->get_data(); data_columns[i] = array_data; diff --git a/regression-test/suites/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.groovy b/regression-test/suites/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.groovy index 6c648d1f0dc29d..7ec3942c331f25 100644 --- a/regression-test/suites/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.groovy +++ b/regression-test/suites/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.groovy @@ -16,6 +16,7 @@ // under the License. suite("test_array_zip_array_enumerate_uniq", "p0") { + sql "set enable_nereids_planner=false;" // ========== array-zip ========== // wrong case try { @@ -50,6 +51,25 @@ suite("test_array_zip_array_enumerate_uniq", "p0") { order_qt_old_sql """SELECT array_enumerate_uniq(array(STDDEV_SAMP(910947.571364)), array(NULL)) from numbers;""" //order_qt_sql """ SELECT max(array_join(arr)) FROM (SELECT array_enumerate_uniq(group_array(DIV(number, 54321)) AS nums, group_array(cast(DIV(number, 98765) as string))) AS arr FROM (SELECT number FROM numbers LIMIT 1000000) GROUP BY bitmap_hash(number) % 100000);""" + sql """ DROP TABLE IF EXISTS ARRAY_BIGINT_DATA;""" + sql """ CREATE TABLE IF NOT EXISTS `ARRAY_BIGINT_DATA` ( + `id` INT NULL, + `data` ARRAY NULL + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + );""" + sql """ INSERT INTO ARRAY_BIGINT_DATA VALUES (0, [-1, 0, 1, 2, -9223372036854775808, 9223372036854775807, 1]);""" + sql """ INSERT INTO ARRAY_BIGINT_DATA VALUES (1, []);""" + + test { + sql """ select array_enumerate_uniq((select data from ARRAY_BIGINT_DATA where id = 0), (select data from ARRAY_BIGINT_DATA where id = 1), (select data from ARRAY_BIGINT_DATA where id = 1));""" + exception ("A subquery should not return Array/Map/Struct type") + } + + // nereids sql "set enable_nereids_planner=true;" sql "set enable_fallback_to_original_planner=false;" @@ -88,6 +108,11 @@ suite("test_array_zip_array_enumerate_uniq", "p0") { order_qt_nereid_sql """SELECT array_enumerate_uniq(array(STDDEV_SAMP(910947.571364)), array(NULL)) from numbers;""" // //order_qt_sql """ SELECT max(array_join(arr)) FROM (SELECT array_enumerate_uniq(group_array(DIV(number, 54321)) AS nums, group_array(cast(DIV(number, 98765) as string))) AS arr FROM (SELECT number FROM numbers LIMIT 1000000) GROUP BY bitmap_hash(number) % 100000);""" + test { + sql """ select array_enumerate_uniq((select data from ARRAY_BIGINT_DATA where id = 0), (select data from ARRAY_BIGINT_DATA where id = 1), (select data from ARRAY_BIGINT_DATA where id = 1));""" + exception ("lengths of all arrays of function array_enumerate_uniq must be equal") + } + // array_shuffle // do not check result, since shuffle result is random sql "SELECT array_sum(array_shuffle([1, 2, 3, 3, null, null, 4, 4])), array_shuffle([1, 2, 3, 3, null, null, 4, 4], 0), shuffle([1, 2, 3, 3, null, null, 4, 4], 0)"