diff --git a/be/src/vec/CMakeLists.txt b/be/src/vec/CMakeLists.txt index b97378e32c..8d2afbce99 100644 --- a/be/src/vec/CMakeLists.txt +++ b/be/src/vec/CMakeLists.txt @@ -159,6 +159,7 @@ set(VEC_FILES functions/array/function_array_difference.cpp functions/array/function_array_enumerate.cpp functions/array/function_array_range.cpp + functions/array/function_array_compact.cpp functions/array/function_array_popback.cpp functions/array/function_array_with_constant.cpp exprs/table_function/vexplode_json_array.cpp diff --git a/be/src/vec/functions/array/function_array_compact.cpp b/be/src/vec/functions/array/function_array_compact.cpp new file mode 100644 index 0000000000..209ff46c20 --- /dev/null +++ b/be/src/vec/functions/array/function_array_compact.cpp @@ -0,0 +1,28 @@ +// 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_compact.h" + +#include "vec/functions/simple_function_factory.h" + +namespace doris::vectorized { + +void register_function_array_compact(SimpleFunctionFactory& factory) { + factory.register_function(); +} + +} // namespace doris::vectorized \ No newline at end of file diff --git a/be/src/vec/functions/array/function_array_compact.h b/be/src/vec/functions/array/function_array_compact.h new file mode 100644 index 0000000000..55488d7631 --- /dev/null +++ b/be/src/vec/functions/array/function_array_compact.h @@ -0,0 +1,110 @@ +// 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 "vec/columns/column_array.h" +#include "vec/data_types/data_type_array.h" +#include "vec/data_types/data_type_number.h" +#include "vec/functions/function.h" + +namespace doris::vectorized { + +class FunctionArrayCompact : public IFunction { +public: + static constexpr auto name = "array_compact"; + static FunctionPtr create() { return std::make_shared(); } + using NullMapType = PaddedPODArray; + + /// 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" + << " and arguments[0] is " << arguments[0]->get_name(); + return arguments[0]; + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) override { + ColumnPtr src_column = + block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + const auto& src_column_array = check_and_get_column(*src_column); + if (!src_column_array) { + return Status::RuntimeError( + fmt::format("unsupported types for function {}({})", get_name(), + block.get_by_position(arguments[0]).type->get_name())); + } + const auto& src_offsets = src_column_array->get_offsets(); + const auto* src_nested_column = &src_column_array->get_data(); + DCHECK(src_nested_column != nullptr); + + DataTypePtr src_column_type = block.get_by_position(arguments[0]).type; + auto nested_type = assert_cast(*src_column_type).get_nested_type(); + auto dest_column_ptr = ColumnArray::create(nested_type->create_column(), + ColumnArray::ColumnOffsets::create()); + IColumn* dest_nested_column = &dest_column_ptr->get_data(); + auto& dest_offsets = dest_column_ptr->get_offsets(); + DCHECK(dest_nested_column != nullptr); + + auto res_val = _execute(*src_nested_column, src_offsets, *dest_nested_column, dest_offsets); + if (!res_val) { + return Status::RuntimeError( + fmt::format("execute failed or unsupported types for function {}({})", + get_name(), block.get_by_position(arguments[0]).type->get_name())); + } + + block.replace_by_position(result, std::move(dest_column_ptr)); + return Status::OK(); + } + +private: + bool _execute(const IColumn& src_column, const ColumnArray::Offsets64& src_offsets, + IColumn& dest_column, ColumnArray::Offsets64& dest_offsets) { + ColumnArray::Offset64 src_offsets_size = src_offsets.size(); + ColumnArray::Offset64 src_pos = 0; + ColumnArray::Offset64 dest_pos = 0; + + for (size_t i = 0; i < src_offsets_size; ++i) { + auto src_offset = src_offsets[i]; + if (src_pos < src_offset) { + // Insert first element + dest_column.insert_from(src_column, src_pos); + + ++src_pos; + ++dest_pos; + + // For the rest of elements, insert if the element is different from the previous. + for (; src_pos < src_offset; ++src_pos) { + if (0 != (src_column.compare_at(src_pos - 1, src_pos, src_column, 1))) { + dest_column.insert_from(src_column, src_pos); + ++dest_pos; + } + } + } + dest_offsets.push_back(dest_pos); + } + return true; + } +}; + +} // namespace doris::vectorized \ No newline at end of file diff --git a/be/src/vec/functions/array/function_array_register.cpp b/be/src/vec/functions/array/function_array_register.cpp index e8c2fd4c0f..82d3b79131 100644 --- a/be/src/vec/functions/array/function_array_register.cpp +++ b/be/src/vec/functions/array/function_array_register.cpp @@ -37,6 +37,7 @@ void register_function_array_slice(SimpleFunctionFactory&); void register_function_array_difference(SimpleFunctionFactory&); void register_function_array_enumerate(SimpleFunctionFactory&); void register_function_array_range(SimpleFunctionFactory&); +void register_function_array_compact(SimpleFunctionFactory&); void register_function_array_popback(SimpleFunctionFactory&); void register_function_array_with_constant(SimpleFunctionFactory&); @@ -56,6 +57,7 @@ void register_function_array(SimpleFunctionFactory& factory) { register_function_array_difference(factory); register_function_array_enumerate(factory); register_function_array_range(factory); + register_function_array_compact(factory); register_function_array_popback(factory); register_function_array_with_constant(factory); } diff --git a/docs/en/docs/sql-manual/sql-functions/array-functions/array_compact.md b/docs/en/docs/sql-manual/sql-functions/array-functions/array_compact.md new file mode 100644 index 0000000000..c125b0c785 --- /dev/null +++ b/docs/en/docs/sql-manual/sql-functions/array-functions/array_compact.md @@ -0,0 +1,81 @@ +--- +{ + "title": "array_compact", + "language": "en" +} +--- + + + +## array_compact + +### description + +Removes consecutive duplicate elements from an array. The order of result values is determined by the order in the source array. + +#### Syntax + +```sql +array_compact(arr) +``` + +#### Arguments + +`arr` — The array to inspect. + +#### Returned value + +The array without continuous duplicate. + +Type: Array. + +### notice + +`Only supported in vectorized engine` + +### example + +``` +select array_compact([1, 2, 3, 3, null, null, 4, 4]); + ++----------------------------------------------------+ +| array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) | ++----------------------------------------------------+ +| [1, 2, 3, NULL, 4] | ++----------------------------------------------------+ + +select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']); + ++-------------------------------------------------------------------------------+ +| array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) | ++-------------------------------------------------------------------------------+ +| ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] | ++-------------------------------------------------------------------------------+ + +select array_compact(['2015-03-13','2015-03-13']); + ++--------------------------------------------------+ +| array_compact(ARRAY('2015-03-13', '2015-03-13')) | ++--------------------------------------------------+ +| ['2015-03-13'] | ++--------------------------------------------------+ +``` + +### keywords + +ARRAY,COMPACT,ARRAY_COMPACT \ No newline at end of file diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_compact.md b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_compact.md new file mode 100644 index 0000000000..c0a308c653 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_compact.md @@ -0,0 +1,81 @@ +--- +{ + "title": "array_compact", + "language": "zh-CN", +} +--- + + + +## array_compact + +### description + +从数组中删除连续的重复元素,结果值的顺序由源数组中的顺序决定。 + +#### Syntax + +```sql +array_compact(arr) +``` + +#### Arguments + +`arr` — 需要处理的数组. + +#### Returned value + +不存在连续重复元素的数组. + +Type: Array. + +### notice + +`只支持在向量化引擎中使用。` + +### example + +``` +select array_compact([1, 2, 3, 3, null, null, 4, 4]); + ++----------------------------------------------------+ +| array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) | ++----------------------------------------------------+ +| [1, 2, 3, NULL, 4] | ++----------------------------------------------------+ + +select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']); + ++-------------------------------------------------------------------------------+ +| array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) | ++-------------------------------------------------------------------------------+ +| ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] | ++-------------------------------------------------------------------------------+ + +select array_compact(['2015-03-13','2015-03-13']); + ++--------------------------------------------------+ +| array_compact(ARRAY('2015-03-13', '2015-03-13')) | ++--------------------------------------------------+ +| ['2015-03-13'] | ++--------------------------------------------------+ +``` + +### keywords + +ARRAY,COMPACT,ARRAY_COMPACT \ No newline at end of file diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py index a09ad77f31..d6c25c9086 100755 --- a/gensrc/script/doris_builtins_functions.py +++ b/gensrc/script/doris_builtins_functions.py @@ -392,6 +392,21 @@ visible_functions = [ [['array_except'], 'ARRAY_VARCHAR', ['ARRAY_VARCHAR', 'ARRAY_VARCHAR'], '', '', '', 'vec', ''], [['array_except'], 'ARRAY_STRING', ['ARRAY_STRING', 'ARRAY_STRING'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_BOOLEAN', ['ARRAY_BOOLEAN'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_TINYINT', ['ARRAY_TINYINT'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_SMALLINT', ['ARRAY_SMALLINT'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_INT', ['ARRAY_INT'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_BIGINT', ['ARRAY_BIGINT'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_LARGEINT', ['ARRAY_LARGEINT'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_DATETIME', ['ARRAY_DATETIME'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_DATE', ['ARRAY_DATE'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_DATETIMEV2', ['ARRAY_DATETIMEV2'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_DATEV2', ['ARRAY_DATEV2'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_FLOAT', ['ARRAY_FLOAT'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_DOUBLE', ['ARRAY_DOUBLE'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_DECIMALV2', ['ARRAY_DECIMALV2'], '', '', '', 'vec', ''], + [['array_compact'], 'ARRAY_VARCHAR', ['ARRAY_VARCHAR'], '', '', '', 'vec', ''], + [['array_intersect'], 'ARRAY_BOOLEAN', ['ARRAY_BOOLEAN', 'ARRAY_BOOLEAN'], '', '', '', 'vec', ''], [['array_intersect'], 'ARRAY_TINYINT', ['ARRAY_TINYINT', 'ARRAY_TINYINT'], '', '', '', 'vec', ''], [['array_intersect'], 'ARRAY_SMALLINT', ['ARRAY_SMALLINT', 'ARRAY_SMALLINT'], '', '', '', 'vec', ''], diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out index 5259da6587..881fc309d2 100644 --- a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out +++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out @@ -7,6 +7,8 @@ 5 0 7 6 9 7 7 5 5 +8 7 4 +9 3 3 -- !select -- 1 3 3 @@ -16,6 +18,8 @@ 5 0 7 6 9 7 7 5 5 +8 7 4 +9 3 3 -- !select -- 1 true @@ -25,6 +29,8 @@ 5 \N 6 \N 7 \N +8 \N +9 true -- !select -- 1 [1, 2, 3] ['a', 'b', ''] @@ -34,6 +40,8 @@ 5 [] ['a', 'b', 'c', 'd'] 6 [1, 2, 3, 4, 5] ['a', 'b', 'c', 'd'] 7 [8, 9, NULL, 10, NULL] ['f', NULL, 'g', NULL, 'h'] +8 [1, 2, 3, 4, NULL] ['a', 'b'] +9 [1, 2, 3] ['a', 'b', ''] -- !select -- [2, 3] 1 @@ -43,6 +51,8 @@ [] 5 [1, 2, 3, 4, 5, 4, 3, 2, 1] 6 [8, 9, NULL, 10, NULL] 7 +[1, 2, 3, 3, 4, 4, NULL] 8 +[1, 2, 3] 9 -- !select -- 1 [1, 2, 3] ['', 'a', 'b'] [1, 2] @@ -52,6 +62,8 @@ 5 [] ['a', 'a', 'b', 'b', 'c', 'c', 'd'] \N 6 [1, 1, 2, 2, 3, 3, 4, 4, 5] ['a', 'a', 'b', 'b', 'c', 'c', 'd'] \N 7 [NULL, NULL, 8, 9, 10] [NULL, NULL, 'f', 'g', 'h'] \N +8 [NULL, 1, 2, 3, 3, 4, 4] ['a', 'b', 'b', 'b'] [1, 2, 2, 3] +9 [1, 2, 3] ['', 'a', 'b'] [1, 2] -- !select -- 1 [1, 2, 3] @@ -61,6 +73,8 @@ 5 \N 6 \N 7 \N +8 [1, 2, 3, 4] +9 [1, 2, 3] -- !select -- 1 [3] @@ -70,6 +84,8 @@ 5 \N 6 \N 7 \N +8 [4] +9 [3] -- !select -- 1 [1, 2] @@ -79,6 +95,8 @@ 5 \N 6 \N 7 \N +8 [1, 2, 3] +9 [1, 2] -- !select -- 1 [2, 3] @@ -88,6 +106,8 @@ 5 [] 6 [2, 3, 4, 5, 4, 3, 2, 1] 7 [9, NULL, 10, NULL] +8 [2, 3, 3, 4, 4, NULL] +9 [2, 3] -- !select -- 1 [1, 2] @@ -97,6 +117,8 @@ 5 [] 6 [1, 2] 7 [8, 9] +8 [1, 2] +9 [1, 2] -- !select -- 1 [3, 2, 1] ['', 'b', 'a'] [2, 1] @@ -106,6 +128,8 @@ 5 [] ['a', 'b', 'c', 'd', 'c', 'b', 'a'] \N 6 [1, 2, 3, 4, 5, 4, 3, 2, 1] ['a', 'b', 'c', 'd', 'c', 'b', 'a'] \N 7 [NULL, 10, NULL, 9, 8] ['h', NULL, 'g', NULL, 'f'] \N +8 [NULL, 4, 4, 3, 3, 2, 1] ['b', 'b', 'b', 'a'] [3, 2, 2, 1] +9 [3, 2, 1] ['', 'b', 'a'] [2, 1] -- !select -- 1 1_2_3 a-b- @@ -115,6 +139,8 @@ 5 a-b-c-d-c-b-a 6 1_2_3_4_5_4_3_2_1 a-b-c-d-c-b-a 7 8_9_null_10_null f-null-g-null-h +8 1_2_3_3_4_4_null a-b-b-b +9 1_2_3 a-b- -- !select -- 1 true @@ -124,6 +150,8 @@ 5 \N 6 \N 7 \N +8 true +9 true -- !select -- 1 false @@ -133,6 +161,8 @@ 5 \N 6 \N 7 \N +8 false +9 false -- !select -- 1 \N @@ -142,6 +172,8 @@ 5 \N 6 \N 7 \N +8 \N +9 \N -- !select -- 1 [1, 2, 3] @@ -151,6 +183,8 @@ 5 [] 6 [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 [1, 2, 3, 4, 5] +8 [1, 2, 3, 4, 5, 6, 7] +9 [1, 2, 3] -- !select -- 1 [1] @@ -160,6 +194,8 @@ 5 \N 6 \N 7 \N +8 [1, 2, 3] +9 [1] -- !select -- 1 [1] @@ -169,6 +205,8 @@ 5 \N 6 \N 7 \N +8 [1] +9 [1, 2, 3] -- !select -- 1 [1] @@ -178,6 +216,8 @@ 5 \N 6 \N 7 \N +8 [1] +9 [1, 2] -- !select -- 1 [1, 2] @@ -187,6 +227,8 @@ 5 [] 6 [1, 2, 3, 4, 5, 4, 3, 2] 7 [8, 9, NULL, 10] +8 [1, 2, 3, 3, 4, 4] +9 [1, 2] -- !select -- 1 [] @@ -196,6 +238,8 @@ 5 \N 6 \N 7 \N +8 ['hi', 'hi'] +9 [] -- !select -- 1 [] @@ -205,6 +249,8 @@ 5 \N 6 \N 7 \N +8 [] +9 [2015-03-13, 2015-03-13] -- !select -- 1 [] @@ -214,6 +260,8 @@ 5 \N 6 \N 7 \N +8 [] +9 [2015-03-13 12:36:38] -- !select -- 1 [1, 1, 1] @@ -223,6 +271,8 @@ 5 [5, 5, 5] 6 [6, 6, 6] 7 [7, 7, 7] +8 [8, 8, 8] +9 [9, 9, 9] -- !select -- 1 [NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL] @@ -232,6 +282,8 @@ 5 [NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL] 6 [NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL] 7 [NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL] +8 [NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL] +9 [NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL] -- !select -- 1 ['a', 'a'] @@ -241,6 +293,8 @@ 5 ['a', 'a'] 6 ['a', 'a'] 7 ['a', 'a'] +8 ['a', 'a'] +9 ['a', 'a'] -- !select -- 1 [123, 123] @@ -250,6 +304,8 @@ 5 [123, 123] 6 [123, 123] 7 [123, 123] +8 [123, 123] +9 [123, 123] -- !select -- \N \N @@ -290,6 +346,72 @@ 8 [] 9 [9] +-- !select -- +1 [1, 2, 3] +2 [4] +3 [] +4 [1, 2, 3, 4, 5, 4, 3, 2, 1] +5 [] +6 [1, 2, 3, 4, 5, 4, 3, 2, 1] +7 [8, 9, NULL, 10, NULL] +8 [1, 2, 3, 4, NULL] +9 [1, 2, 3] + +-- !select -- +1 ['a', 'b', ''] +2 \N +3 [] +4 [] +5 ['a', 'b', 'c', 'd', 'c', 'b', 'a'] +6 ['a', 'b', 'c', 'd', 'c', 'b', 'a'] +7 ['f', NULL, 'g', NULL, 'h'] +8 ['a', 'b'] +9 ['a', 'b', ''] + +-- !select -- +1 [1, 2] +2 [5] +3 \N +4 [] +5 \N +6 \N +7 \N +8 [1, 2, 3] +9 [1, 2] + +-- !select -- +1 ['hi'] +2 ['hi2'] +3 ['hi3'] +4 \N +5 \N +6 \N +7 \N +8 ['hi', 'hello'] +9 ['hi'] + +-- !select -- +1 [2015-03-13] +2 \N +3 \N +4 \N +5 \N +6 \N +7 \N +8 [2015-03-13] +9 [2015-03-13, 2015-03-14] + +-- !select -- +1 [2015-03-13 12:36:38] +2 \N +3 \N +4 \N +5 \N +6 \N +7 \N +8 [2015-03-13 12:36:38] +9 [2015-03-13 12:36:38] + -- !select -- [1, 2, 3] 1,2,3 [4] 4 @@ -298,4 +420,6 @@ [] [1, 2, 3, 4, 5, 4, 3, 2, 1] 1,2,3,4,5 [8, 9, NULL, 10, NULL] \N +[1, 2, 3, 3, 4, 4, NULL] \N +[1, 2, 3] 1,2,3,4,8,9 diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out index 6e746f26ab..137e978241 100644 --- a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out +++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out @@ -389,3 +389,21 @@ _ -- !sql -- [NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL] +-- !sql -- +[1, 2, 3, NULL, 4] + +-- !sql -- +[NULL] + +-- !sql -- +[1.2, 3.4, 3.3, 2.1] + +-- !sql -- +['a', 'b', 'c', 'd'] + +-- !sql -- +['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] + +-- !sql -- +['2015-03-13'] + diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy index b3137feb1d..cc478364e0 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy @@ -45,6 +45,8 @@ suite("test_array_functions") { sql """ INSERT INTO ${tableName} VALUES(5,[],["a","b","c","d","c","b","a"],NULL,NULL,NULL,NULL) """ sql """ INSERT INTO ${tableName} VALUES(6,[1,2,3,4,5,4,3,2,1],["a","b","c","d","c","b","a"],NULL,NULL,NULL,NULL) """ sql """ INSERT INTO ${tableName} VALUES(7,[8,9,NULL,10,NULL],["f",NULL,"g",NULL,"h"],NULL,NULL,NULL,NULL) """ + sql """ INSERT INTO ${tableName} VALUES(8,[1,2,3,3,4,4,NULL],["a","b","b","b"],[1,2,2,3],["hi","hi","hello"],["2015-03-13"],["2015-03-13 12:36:38"]) """ + sql """ INSERT INTO ${tableName} VALUES(9,[1,2,3],["a","b",""],[1,2],["hi"],["2015-03-13","2015-03-13","2015-03-14"],["2015-03-13 12:36:38","2015-03-13 12:36:38"]) """ qt_select "SELECT k1, size(k2), size(k3) FROM ${tableName} ORDER BY k1" qt_select "SELECT k1, cardinality(k2), cardinality(k3) FROM ${tableName} ORDER BY k1" @@ -105,6 +107,13 @@ suite("test_array_functions") { qt_select "SELECT k1, array_range(k1) from ${tableName2} ORDER BY k1" qt_select "SELECT k1, array_range(k1,k2) from ${tableName2} ORDER BY k1" qt_select "SELECT k1, array_range(k1,k2,k3) from ${tableName2} ORDER BY k1" + qt_select "SELECT k1, array_compact(k2) from ${tableName} ORDER BY k1" + qt_select "SELECT k1, array_compact(k3) from ${tableName} ORDER BY k1" + qt_select "SELECT k1, array_compact(k4) from ${tableName} ORDER BY k1" + qt_select "SELECT k1, array_compact(k5) from ${tableName} ORDER BY k1" + qt_select "SELECT k1, array_compact(k6) from ${tableName} ORDER BY k1" + qt_select "SELECT k1, array_compact(k7) from ${tableName} ORDER BY k1" + qt_select "select k2, bitmap_to_string(bitmap_from_array(k2)) from ${tableName} order by k1;" } diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy index 8dc62e8d98..37f3f8037f 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy @@ -172,6 +172,15 @@ suite("test_array_functions_by_literal") { qt_sql "select array_with_constant(2, '1')" qt_sql "select array_with_constant(4, 1223)" qt_sql "select array_with_constant(8, null)" + + // array_compact function + qt_sql "select array_compact([1, 2, 3, 3, null, null, 4, 4])" + qt_sql "select array_compact([null, null, null])" + qt_sql "select array_compact([1.2, 1.2, 3.4, 3.3, 2.1])" + qt_sql "select array_compact(['a','b','c','c','d'])" + qt_sql "select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd'])" + qt_sql "select array_compact(['2015-03-13','2015-03-13'])" + // abnormal test test { sql "select array_intersect([1, 2, 3, 1, 2, 3], '1[3, 2, 5]')"