From dc28878f0e0a11aa5bdcd069820050755efffb5a Mon Sep 17 00:00:00 2001 From: amory Date: Wed, 6 Sep 2023 14:32:06 +0800 Subject: [PATCH] [FIX](function) fix size function for array map (#23920) Issue Number: close #xxx now we use select size(map(1, 2)); which will make be core and we can make size function handle array & map column both --- .../array/function_array_register.cpp | 2 - .../functions/array/function_array_size.cpp | 30 - .../vec/functions/array/function_array_size.h | 89 -- be/src/vec/functions/function_map.cpp | 59 -- be/src/vec/functions/function_size.cpp | 107 +++ .../vec/functions/simple_function_factory.h | 2 + .../functions/scalar/Cardinality.java | 5 +- .../scalar_function/Map.out | 812 ++++++++++++++++++ .../size_funciton/test_size_function.out | 31 + .../scalar_function/Map.groovy | 58 ++ .../size_funciton/test_size_function.groovy | 56 ++ 11 files changed, 1070 insertions(+), 181 deletions(-) delete mode 100644 be/src/vec/functions/array/function_array_size.cpp delete mode 100644 be/src/vec/functions/array/function_array_size.h create mode 100644 be/src/vec/functions/function_size.cpp create mode 100644 regression-test/data/query_p0/sql_functions/size_funciton/test_size_function.out create mode 100644 regression-test/suites/query_p0/sql_functions/size_funciton/test_size_function.groovy diff --git a/be/src/vec/functions/array/function_array_register.cpp b/be/src/vec/functions/array/function_array_register.cpp index aebb9defd3..0a0cb5a96d 100644 --- a/be/src/vec/functions/array/function_array_register.cpp +++ b/be/src/vec/functions/array/function_array_register.cpp @@ -26,7 +26,6 @@ void register_function_array_shuffle(SimpleFunctionFactory&); void register_function_array_exists(SimpleFunctionFactory&); void register_function_array_element(SimpleFunctionFactory&); void register_function_array_index(SimpleFunctionFactory&); -void register_function_array_size(SimpleFunctionFactory&); void register_function_array_aggregation(SimpleFunctionFactory&); void register_function_array_distance(SimpleFunctionFactory&); void register_function_array_distinct(SimpleFunctionFactory&); @@ -61,7 +60,6 @@ void register_function_array(SimpleFunctionFactory& factory) { register_function_array_exists(factory); register_function_array_element(factory); register_function_array_index(factory); - register_function_array_size(factory); register_function_array_aggregation(factory); register_function_array_distance(factory); register_function_array_distinct(factory); diff --git a/be/src/vec/functions/array/function_array_size.cpp b/be/src/vec/functions/array/function_array_size.cpp deleted file mode 100644 index 3c1fc42025..0000000000 --- a/be/src/vec/functions/array/function_array_size.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#include "vec/functions/array/function_array_size.h" - -#include "vec/functions/simple_function_factory.h" - -namespace doris::vectorized { - -void register_function_array_size(SimpleFunctionFactory& factory) { - factory.register_function(); - factory.register_alias(FunctionArraySize::name, "cardinality"); - factory.register_alias(FunctionArraySize::name, "array_size"); -} - -} // namespace doris::vectorized diff --git a/be/src/vec/functions/array/function_array_size.h b/be/src/vec/functions/array/function_array_size.h deleted file mode 100644 index deb46970b8..0000000000 --- a/be/src/vec/functions/array/function_array_size.h +++ /dev/null @@ -1,89 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include - -#include "common/status.h" -#include "vec/columns/column.h" -#include "vec/columns/column_array.h" -#include "vec/columns/column_vector.h" -#include "vec/columns/columns_number.h" -#include "vec/core/block.h" -#include "vec/core/column_numbers.h" -#include "vec/core/column_with_type_and_name.h" -#include "vec/core/types.h" -#include "vec/data_types/data_type.h" -#include "vec/data_types/data_type_number.h" -#include "vec/functions/function.h" - -namespace doris { -class FunctionContext; -} // namespace doris - -namespace doris::vectorized { - -class FunctionArraySize : public IFunction { -public: - static constexpr auto name = "size"; - static FunctionPtr create() { return std::make_shared(); } - - /// Get function name. - String get_name() const override { return name; } - - bool is_variadic() const override { return false; } - - size_t get_number_of_arguments() const override { return 1; } - - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - DCHECK(is_array(arguments[0])) - << "first argument for function: " << name << " should be DataTypeArray"; - return std::make_shared(); - } - - Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, - size_t result, size_t input_rows_count) override { - auto left_column = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); - const auto array_column = check_and_get_column(*left_column); - if (!array_column) { - return Status::RuntimeError("unsupported types for function {}({})", get_name(), - block.get_by_position(arguments[0]).type->get_name()); - } - const auto& offsets = array_column->get_offsets(); - - auto dst_column = ColumnInt64::create(input_rows_count); - auto& dst_data = dst_column->get_data(); - - for (ssize_t i = 0; i < offsets.size(); ++i) { - dst_data[i] = offsets[i] - offsets[i - 1]; - } - - block.replace_by_position(result, std::move(dst_column)); - return Status::OK(); - } -}; - -} // namespace doris::vectorized diff --git a/be/src/vec/functions/function_map.cpp b/be/src/vec/functions/function_map.cpp index 3f847b4190..eb21b6f839 100644 --- a/be/src/vec/functions/function_map.cpp +++ b/be/src/vec/functions/function_map.cpp @@ -146,64 +146,6 @@ public: } }; -class FunctionMapSize : public IFunction { -public: - static constexpr auto name = "map_size"; - static FunctionPtr create() { return std::make_shared(); } - - /// Get function name. - String get_name() const override { return name; } - - bool is_variadic() const override { return false; } - - size_t get_number_of_arguments() const override { return 1; } - - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - DataTypePtr datatype = arguments[0]; - if (datatype->is_nullable()) { - datatype = assert_cast(datatype.get())->get_nested_type(); - } - DCHECK(is_map(datatype)) << "first argument for function: " << name - << " should be DataTypeMap"; - return std::make_shared(); - } - - Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, - size_t result, size_t input_rows_count) override { - const auto& [left_column, left_const] = - unpack_if_const(block.get_by_position(arguments[0]).column); - const ColumnMap* map_column = nullptr; - // const UInt8* map_null_map = nullptr; - if (left_column->is_nullable()) { - auto nullable_column = reinterpret_cast(left_column.get()); - map_column = check_and_get_column(nullable_column->get_nested_column()); - // map_null_map = nullable_column->get_null_map_column().get_data().data(); - } else { - map_column = check_and_get_column(*left_column.get()); - } - if (!map_column) { - return Status::RuntimeError("unsupported types for function {}({})", get_name(), - block.get_by_position(arguments[0]).type->get_name()); - } - - auto dst_column = ColumnInt64::create(input_rows_count); - auto& dst_data = dst_column->get_data(); - - if (left_const) { - for (size_t i = 0; i < map_column->size(); i++) { - dst_data[i] = map_column->size_at(0); - } - } else { - for (size_t i = 0; i < map_column->size(); i++) { - dst_data[i] = map_column->size_at(i); - } - } - - block.replace_by_position(result, std::move(dst_column)); - return Status::OK(); - } -}; - template class FunctionMapContains : public IFunction { public: @@ -354,7 +296,6 @@ public: void register_function_map(SimpleFunctionFactory& factory) { factory.register_function(); - factory.register_function(); factory.register_function>(); factory.register_function>(); factory.register_function>(); diff --git a/be/src/vec/functions/function_size.cpp b/be/src/vec/functions/function_size.cpp new file mode 100644 index 0000000000..988f909443 --- /dev/null +++ b/be/src/vec/functions/function_size.cpp @@ -0,0 +1,107 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "simple_function_factory.h" +#include "vec/columns/column_array.h" +#include "vec/columns/column_map.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" +#include "vec/functions/function.h" +#include "vec/functions/function_helpers.h" + +namespace doris::vectorized { + +// size function for size with map and array +class FunctionSize : public IFunction { +public: + static constexpr auto name = "size"; + static FunctionPtr create() { return std::make_shared(); } + String get_name() const override { return name; } + 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]; + if (datatype->is_nullable()) { + datatype = assert_cast(datatype.get())->get_nested_type(); + } + DCHECK(is_map(datatype) || is_array(datatype)) << "first argument for function: " << name + << " should be DataTypeMap or DataTypeArray"; + return std::make_shared(); + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) override { + const auto& [left_column, left_const] = + unpack_if_const(block.get_by_position(arguments[0]).column); + const auto type = block.get_by_position(arguments[0]).type; + const ColumnArray* array_column = nullptr; + const ColumnMap* map_column = nullptr; + if (is_array(type)) { + if (left_column->is_nullable()) { + auto nullable_column = reinterpret_cast(left_column.get()); + array_column = + check_and_get_column(nullable_column->get_nested_column()); + } else { + array_column = check_and_get_column(*left_column.get()); + } + } else if (is_map(type)) { + if (left_column->is_nullable()) { + auto nullable_column = reinterpret_cast(left_column.get()); + map_column = check_and_get_column(nullable_column->get_nested_column()); + } else { + map_column = check_and_get_column(*left_column.get()); + } + } + + auto dst_column = ColumnInt64::create(input_rows_count); + auto& dst_data = dst_column->get_data(); + + if (left_const && map_column) { + for (size_t i = 0; i < map_column->size(); i++) { + dst_data[i] = map_column->size_at(0); + } + } else if (left_const && array_column) { + for (size_t i = 0; i < array_column->size(); i++) { + dst_data[i] = array_column->size_at(0); + } + } else if (map_column) { + for (size_t i = 0; i < map_column->size(); i++) { + dst_data[i] = map_column->size_at(i); + } + } else if (array_column) { + for (size_t i = 0; i < array_column->size(); i++) { + dst_data[i] = array_column->size_at(i); + } + } else { + return Status::RuntimeError("unsupported types for function {}({})", get_name(), + block.get_by_position(arguments[0]).type->get_name()); + } + + block.replace_by_position(result, std::move(dst_column)); + return Status::OK(); + } +}; + +void register_function_size(SimpleFunctionFactory& factory) { + factory.register_function(); + factory.register_alias(FunctionSize::name, "map_size"); + factory.register_alias(FunctionSize::name, "cardinality"); + factory.register_alias(FunctionSize::name, "array_size"); +} +} // namespace doris::vectorized \ No newline at end of file diff --git a/be/src/vec/functions/simple_function_factory.h b/be/src/vec/functions/simple_function_factory.h index 77f9c73671..b5e72bdde6 100644 --- a/be/src/vec/functions/simple_function_factory.h +++ b/be/src/vec/functions/simple_function_factory.h @@ -32,6 +32,7 @@ namespace doris::vectorized { class SimpleFunctionFactory; +void register_function_size(SimpleFunctionFactory& factory); void register_function_comparison(SimpleFunctionFactory& factory); void register_function_comparison_eq_for_null(SimpleFunctionFactory& factory); void register_function_hll_cardinality(SimpleFunctionFactory& factory); @@ -207,6 +208,7 @@ public: static std::once_flag oc; static SimpleFunctionFactory instance; std::call_once(oc, []() { + register_function_size(instance); register_function_bitmap(instance); register_function_quantile_state(instance); register_function_bitmap_variadic(instance); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cardinality.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cardinality.java index 90da3f3f1d..c74518a6da 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cardinality.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cardinality.java @@ -25,6 +25,7 @@ import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.BigIntType; +import org.apache.doris.nereids.types.MapType; import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; @@ -39,7 +40,9 @@ public class Cardinality extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) + FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)), + FunctionSignature.ret(BigIntType.INSTANCE).args(MapType.of(AnyDataType.INSTANCE_WITHOUT_INDEX, + AnyDataType.INSTANCE_WITHOUT_INDEX)) ); /** diff --git a/regression-test/data/nereids_function_p0/scalar_function/Map.out b/regression-test/data/nereids_function_p0/scalar_function/Map.out index ca4185da38..6c3f716719 100644 --- a/regression-test/data/nereids_function_p0/scalar_function/Map.out +++ b/regression-test/data/nereids_function_p0/scalar_function/Map.out @@ -1217,6 +1217,818 @@ 2 2 +-- !size_bool_tint -- +\N +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 + +-- !size_tint_tint -- +\N +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 + +-- !size_sint_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_int_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_bint_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_lint_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_float_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_dbl_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_dcml_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_chr_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_vchr_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_str_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_date_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_dtm_tint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_bool -- +\N +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 + +-- !size_int_int -- +\N +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 + +-- !size_tint_sint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_int -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_bint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_lint -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_float -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_dbl -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_dcml -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_chr -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_vchr -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_str -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_date -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_dtm -- +\N +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_bool_tint_notnull -- +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 + +-- !size_tint_tint_notnull -- +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 + +-- !size_sint_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_int_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_bint_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_lint_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_float_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_dbl_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_dcml_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_chr_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_vchr_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_str_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_date_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_dtm_tint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_bool_notnull -- +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 + +-- !size_int_int_notnull -- +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 +3 + +-- !size_tint_sint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_int_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_bint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_lint_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_float_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_dbl_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_dcml_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_chr_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_vchr_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_str_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_date_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + +-- !size_tint_dtm_notnull -- +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + -- !map_keys_bool_tint -- \N [NULL, 0, 0] diff --git a/regression-test/data/query_p0/sql_functions/size_funciton/test_size_function.out b/regression-test/data/query_p0/sql_functions/size_funciton/test_size_function.out new file mode 100644 index 0000000000..0c31b5dab0 --- /dev/null +++ b/regression-test/data/query_p0/sql_functions/size_funciton/test_size_function.out @@ -0,0 +1,31 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +4 ["aaa", "bbb", NULL, "fff"] ["aaa", "bbb", NULL, "fff"] + +-- !sql -- +4 ["2020-01-02", "2021-01-01", "2022-01-03", "1996-04-17"] ["2020-01-02", "2021-01-01", "2022-01-03", "1996-04-17"] + +-- !sql -- +4 ["aaa", "bbb", NULL, "fff"] ["aaa", "bbb", NULL, "fff"] + +-- !sql -- +4 ["2020-01-02", "2021-01-01", "2022-01-03", "1996-04-17"] ["2020-01-02", "2021-01-01", "2022-01-03", "1996-04-17"] + +-- !sql -- +4 ["aaa", "bbb", NULL, "fff"] ["aaa", "bbb", NULL, "fff"] + +-- !sql -- +4 ["2020-01-02", "2021-01-01", "2022-01-03", "1996-04-17"] ["2020-01-02", "2021-01-01", "2022-01-03", "1996-04-17"] + +-- !sql -- +2 + +-- !sql -- +2 + +-- !select_00 -- +1 3 3 +5 3 0 +5 3 3 +4 3 2 + diff --git a/regression-test/suites/nereids_function_p0/scalar_function/Map.groovy b/regression-test/suites/nereids_function_p0/scalar_function/Map.groovy index 6f3626ce24..f8b28c8da9 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/Map.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/Map.groovy @@ -108,6 +108,64 @@ suite("nereids_scalar_fn_map") { order_qt_map_size_tint_date_notnull """ select map_size(km_tint_date) from fn_test_not_nullable """ order_qt_map_size_tint_dtm_notnull """ select map_size(km_tint_dtm) from fn_test_not_nullable """ + // size same with map_size + order_qt_size_bool_tint """ select size(km_bool_tint) from fn_test """ + order_qt_size_tint_tint """ select size(km_tint_tint) from fn_test """ + order_qt_size_sint_tint """ select size(km_sint_tint) from fn_test """ + order_qt_size_int_tint """ select size(km_int_tint) from fn_test """ + order_qt_size_bint_tint """ select size(km_bint_tint) from fn_test """ + order_qt_size_lint_tint """ select size(km_lint_tint) from fn_test """ + order_qt_size_float_tint """ select size(km_float_tint) from fn_test """ + order_qt_size_dbl_tint """ select size(km_dbl_tint) from fn_test """ + order_qt_size_dcml_tint """ select size(km_dcml_tint) from fn_test """ + order_qt_size_chr_tint """ select size(km_chr_tint) from fn_test """ + order_qt_size_vchr_tint """ select size(km_vchr_tint) from fn_test """ + order_qt_size_str_tint """ select size(km_str_tint) from fn_test """ + order_qt_size_date_tint """ select size(km_date_tint) from fn_test """ + order_qt_size_dtm_tint """ select size(km_dtm_tint) from fn_test """ + order_qt_size_tint_bool """ select size(km_tint_bool) from fn_test """ + order_qt_size_int_int """ select size(km_int_int) from fn_test """ + order_qt_size_tint_sint """ select size(km_tint_sint) from fn_test """ + order_qt_size_tint_int """ select size(km_tint_int) from fn_test """ + order_qt_size_tint_bint """ select size(km_tint_bint) from fn_test """ + order_qt_size_tint_lint """ select size(km_tint_lint) from fn_test """ + order_qt_size_tint_float """ select size(km_tint_float) from fn_test """ + order_qt_size_tint_dbl """ select size(km_tint_dbl) from fn_test """ + order_qt_size_tint_dcml """ select size(km_tint_dcml) from fn_test """ + order_qt_size_tint_chr """ select size(km_tint_chr) from fn_test """ + order_qt_size_tint_vchr """ select size(km_tint_vchr) from fn_test """ + order_qt_size_tint_str """ select size(km_tint_str) from fn_test """ + order_qt_size_tint_date """ select size(km_tint_date) from fn_test """ + order_qt_size_tint_dtm """ select size(km_tint_dtm) from fn_test """ + order_qt_size_bool_tint_notnull """ select size(km_bool_tint) from fn_test_not_nullable """ + order_qt_size_tint_tint_notnull """ select size(km_tint_tint) from fn_test_not_nullable """ + order_qt_size_sint_tint_notnull """ select size(km_sint_tint) from fn_test_not_nullable """ + order_qt_size_int_tint_notnull """ select size(km_int_tint) from fn_test_not_nullable """ + order_qt_size_bint_tint_notnull """ select size(km_bint_tint) from fn_test_not_nullable """ + order_qt_size_lint_tint_notnull """ select size(km_lint_tint) from fn_test_not_nullable """ + order_qt_size_float_tint_notnull """ select size(km_float_tint) from fn_test_not_nullable """ + order_qt_size_dbl_tint_notnull """ select size(km_dbl_tint) from fn_test_not_nullable """ + order_qt_size_dcml_tint_notnull """ select size(km_dcml_tint) from fn_test_not_nullable """ + order_qt_size_chr_tint_notnull """ select size(km_chr_tint) from fn_test_not_nullable """ + order_qt_size_vchr_tint_notnull """ select size(km_vchr_tint) from fn_test_not_nullable """ + order_qt_size_str_tint_notnull """ select size(km_str_tint) from fn_test_not_nullable """ + order_qt_size_date_tint_notnull """ select size(km_date_tint) from fn_test_not_nullable """ + order_qt_size_dtm_tint_notnull """ select size(km_dtm_tint) from fn_test_not_nullable """ + order_qt_size_tint_bool_notnull """ select size(km_tint_bool) from fn_test_not_nullable """ + order_qt_size_int_int_notnull """ select size(km_int_int) from fn_test_not_nullable """ + order_qt_size_tint_sint_notnull """ select size(km_tint_sint) from fn_test_not_nullable """ + order_qt_size_tint_int_notnull """ select size(km_tint_int) from fn_test_not_nullable """ + order_qt_size_tint_bint_notnull """ select size(km_tint_bint) from fn_test_not_nullable """ + order_qt_size_tint_lint_notnull """ select size(km_tint_lint) from fn_test_not_nullable """ + order_qt_size_tint_float_notnull """ select size(km_tint_float) from fn_test_not_nullable """ + order_qt_size_tint_dbl_notnull """ select size(km_tint_dbl) from fn_test_not_nullable """ + order_qt_size_tint_dcml_notnull """ select size(km_tint_dcml) from fn_test_not_nullable """ + order_qt_size_tint_chr_notnull """ select size(km_tint_chr) from fn_test_not_nullable """ + order_qt_size_tint_vchr_notnull """ select size(km_tint_vchr) from fn_test_not_nullable """ + order_qt_size_tint_str_notnull """ select size(km_tint_str) from fn_test_not_nullable """ + order_qt_size_tint_date_notnull """ select size(km_tint_date) from fn_test_not_nullable """ + order_qt_size_tint_dtm_notnull """ select size(km_tint_dtm) from fn_test_not_nullable """ + // map_keys order_qt_map_keys_bool_tint """ select map_keys(km_bool_tint) from fn_test """ order_qt_map_keys_tint_tint """ select map_keys(km_tint_tint) from fn_test """ diff --git a/regression-test/suites/query_p0/sql_functions/size_funciton/test_size_function.groovy b/regression-test/suites/query_p0/sql_functions/size_funciton/test_size_function.groovy new file mode 100644 index 0000000000..fe2607ecb1 --- /dev/null +++ b/regression-test/suites/query_p0/sql_functions/size_funciton/test_size_function.groovy @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_size_function") { + sql """ set enable_nereids_planner = false; """ + // literal + + qt_sql "SELECT size(array_shuffle(['aaa', null, 'bbb', 'fff'])), array_shuffle(['aaa', null, 'bbb', 'fff'], 0), shuffle(['aaa', null, 'bbb', 'fff'], 0)" + qt_sql """select size(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17")), array_shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0), shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0)""" + qt_sql "SELECT array_size(array_shuffle(['aaa', null, 'bbb', 'fff'])), array_shuffle(['aaa', null, 'bbb', 'fff'], 0), shuffle(['aaa', null, 'bbb', 'fff'], 0)" + qt_sql """select array_size(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17")), array_shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0), shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0)""" + qt_sql "SELECT (cardinality(['aaa', null, 'bbb', 'fff'])), array_shuffle(['aaa', null, 'bbb', 'fff'], 0), shuffle(['aaa', null, 'bbb', 'fff'], 0)" + qt_sql """select cardinality(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17")), array_shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0), shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0)""" + + qt_sql "SELECT size(map(1,2,2,null));" + qt_sql "SELECT map_size(map(1,2,2,null));" + + // table + def tableName = "test_size" + sql "DROP TABLE IF EXISTS ${tableName}" + sql """ + CREATE TABLE IF NOT EXISTS `${tableName}` ( + `id` int(11) NULL, + `c_array1` array NULL, + `c_array2` array NULL, + `c_map` map NULL, + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "storage_format" = "V2" + ) + """ + sql """INSERT INTO ${tableName} values + (0, [2], ['123', '124', '125'], {1: "", null: "a", 2: "b"}), + (1, [1,2,3,4,5], ['234', '124', '125'], {}), + (2, [1,2,10,12,10], ['345', '234', '123'], {1: "a", 2: "b", 3: "c"}), + (3, [1,3,4,2], ['222', '444', '555'], {11: NULL, 0:"ss"}); + """ + qt_select_00 " select size(c_array1), size(c_array2), size(c_map) from ${tableName} order by id;" +} \ No newline at end of file