[pick](array-funcs)pick array func array_enumerate_uniq bugfix (#38721)

## Proposed changes
backport: https://github.com/apache/doris/pull/38384
Issue Number: close #xxx

<!--Describe your changes.-->
This commit is contained in:
amory
2024-08-02 11:25:17 +08:00
committed by GitHub
parent f5bc65989c
commit 1d982ada45
3 changed files with 28 additions and 7 deletions

View File

@ -56,7 +56,6 @@ public:
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 =

View File

@ -76,7 +76,6 @@ public:
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()) {
@ -93,15 +92,13 @@ public:
" 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;
@ -145,7 +142,7 @@ public:
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;

View File

@ -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<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;"
@ -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)"