Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion be/src/vec/functions/array/function_array_enumerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class FunctionArrayEnumerate : public IFunction {
static constexpr auto name = "array_enumerate";
static FunctionPtr create() { return std::make_shared<FunctionArrayEnumerate>(); }
String get_name() const override { return name; }
bool use_default_implementation_for_nulls() const override { return false; }
size_t get_number_of_arguments() const override { return 1; }
DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
const DataTypeArray* array_type =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ 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; }

DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
if (arguments.empty()) {
Expand All @@ -93,15 +92,13 @@ class FunctionArrayEnumerateUniq : public IFunction {
" must be an array but it has type " +
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<DataTypeInt64>();
DataTypePtr return_type = std::make_shared<DataTypeArray>(
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;
Expand Down Expand Up @@ -145,7 +142,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<BIGINT> 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;"
Expand Down Expand Up @@ -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)"
Expand Down