This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 5dc01968fc0 [fix](funcs) map struct construct funcs #39699 (#40502)
5dc01968fc0 is described below
commit 5dc01968fc021f9d48e80656a94a2f73476231cb
Author: Kang <[email protected]>
AuthorDate: Mon Sep 9 14:18:04 2024 +0800
[fix](funcs) map struct construct funcs #39699 (#40502)
Co-authored-by: amory <[email protected]>
---
be/src/vec/functions/function.h | 7 ++--
be/src/vec/functions/function_map.cpp | 14 +++----
be/src/vec/functions/function_struct.cpp | 7 ++--
.../query/map_functions/test_map_with_agg.out | 9 ++++
.../query/map_functions/test_map_with_agg.groovy | 48 ++++++++++++++++++++++
5 files changed, 72 insertions(+), 13 deletions(-)
diff --git a/be/src/vec/functions/function.h b/be/src/vec/functions/function.h
index 4c6340e5b73..0d055d8ca22 100644
--- a/be/src/vec/functions/function.h
+++ b/be/src/vec/functions/function.h
@@ -447,9 +447,10 @@ public:
bool is_stateful() const override { return false; }
- /// TODO: make const
- Status execute_impl(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
- size_t result, size_t input_rows_count) override = 0;
+ /// Notice: We should not change the column in the block, because the
column may be shared by multiple expressions or exec nodes.
+ virtual Status execute_impl(FunctionContext* context, Block& block,
+ const ColumnNumbers& arguments, size_t result,
+ size_t input_rows_count) override = 0;
/// Override this functions to change default implementation behavior. See
details in IMyFunction.
bool use_default_implementation_for_nulls() const override { return true; }
diff --git a/be/src/vec/functions/function_map.cpp
b/be/src/vec/functions/function_map.cpp
index a71c19ec456..f612685b676 100644
--- a/be/src/vec/functions/function_map.cpp
+++ b/be/src/vec/functions/function_map.cpp
@@ -116,15 +116,17 @@ public:
auto& result_col_map_offsets = map_column->get_offsets();
result_col_map_offsets.resize(input_rows_count);
- std::unique_ptr<bool[]> col_const =
std::make_unique<bool[]>(num_element);
+ std::unique_ptr<bool[]> col_const =
std::make_unique_for_overwrite<bool[]>(num_element);
+ std::vector<ColumnPtr> arg(num_element);
for (size_t i = 0; i < num_element; ++i) {
auto& col = block.get_by_position(arguments[i]).column;
std::tie(col, col_const[i]) = unpack_if_const(col);
bool is_nullable = i % 2 == 0 ?
result_col_map_keys_data.is_nullable()
:
result_col_map_vals_data.is_nullable();
// convert to nullable column
+ arg[i] = col;
if (is_nullable && !col->is_nullable()) {
- col = ColumnNullable::create(col,
ColumnUInt8::create(col->size(), 0));
+ arg[i] = ColumnNullable::create(col,
ColumnUInt8::create(col->size(), 0));
}
}
@@ -132,11 +134,9 @@ public:
ColumnArray::Offset64 offset = 0;
for (size_t row = 0; row < input_rows_count; ++row) {
for (size_t i = 0; i < num_element; i += 2) {
-
result_col_map_keys_data.insert_from(*block.get_by_position(arguments[i]).column,
- index_check_const(row,
col_const[i]));
- result_col_map_vals_data.insert_from(
- *block.get_by_position(arguments[i + 1]).column,
- index_check_const(row, col_const[i + 1]));
+ result_col_map_keys_data.insert_from(*arg[i],
index_check_const(row, col_const[i]));
+ result_col_map_vals_data.insert_from(*arg[i + 1],
+ index_check_const(row,
col_const[i + 1]));
}
offset += num_element / 2;
result_col_map_offsets[row] = offset;
diff --git a/be/src/vec/functions/function_struct.cpp
b/be/src/vec/functions/function_struct.cpp
index 0343d3b6166..7e1a53e72f6 100644
--- a/be/src/vec/functions/function_struct.cpp
+++ b/be/src/vec/functions/function_struct.cpp
@@ -93,21 +93,22 @@ public:
"function {} args number {} is not equal to result struct
field number {}.",
get_name(), num_element, struct_column->tuple_size());
}
+ std::vector<ColumnPtr> arg(num_element);
for (size_t i = 0; i < num_element; ++i) {
auto& nested_col = struct_column->get_column(i);
nested_col.reserve(input_rows_count);
bool is_nullable = nested_col.is_nullable();
auto& col = block.get_by_position(args_num[i]).column;
col = col->convert_to_full_column_if_const();
+ arg[i] = col;
if (is_nullable && !col->is_nullable()) {
- col = ColumnNullable::create(col,
ColumnUInt8::create(col->size(), 0));
+ arg[i] = ColumnNullable::create(col,
ColumnUInt8::create(col->size(), 0));
}
}
// insert value into struct column by column
for (size_t i = 0; i < num_element; ++i) {
- struct_column->get_column(i).insert_range_from(
- *block.get_by_position(args_num[i]).column, 0,
input_rows_count);
+ struct_column->get_column(i).insert_range_from(*arg[i], 0,
input_rows_count);
}
block.replace_by_position(result, std::move(result_col));
return Status::OK();
diff --git
a/regression-test/data/datatype_p0/nested_types/query/map_functions/test_map_with_agg.out
b/regression-test/data/datatype_p0/nested_types/query/map_functions/test_map_with_agg.out
new file mode 100644
index 00000000000..c89a6f7e8a1
--- /dev/null
+++
b/regression-test/data/datatype_p0/nested_types/query/map_functions/test_map_with_agg.out
@@ -0,0 +1,9 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !old_sql --
+1 expr_seach {"exp_seac":8}
+1 express_search {"exp_seac":6}
+
+-- !nereid_sql --
+1 expr_seach {"exp_seac":8}
+1 express_search {"exp_seac":6}
+
diff --git
a/regression-test/suites/datatype_p0/nested_types/query/map_functions/test_map_with_agg.groovy
b/regression-test/suites/datatype_p0/nested_types/query/map_functions/test_map_with_agg.groovy
new file mode 100644
index 00000000000..c3209ee1ddd
--- /dev/null
+++
b/regression-test/suites/datatype_p0/nested_types/query/map_functions/test_map_with_agg.groovy
@@ -0,0 +1,48 @@
+// 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_map_with_agg", "p0") {
+ // create table
+ sql """ DROP TABLE IF EXISTS t_map_count;"""
+ sql """ CREATE TABLE IF NOT EXISTS t_map_count(id int(11), c_char
VARCHAR(20), p1 varchar(200), p2 varchar(200), et VARCHAR(30), uid VARCHAR(100))
+ ENGINE=OLAP DUPLICATE KEY(`id`, `c_char`, `p1`) DISTRIBUTED BY HASH(id)
BUCKETS 1 PROPERTIES('replication_num' = '1');"""
+
+ // insert data
+ sql """ INSERT INTO t_map_count VALUES(1,
'express_search','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'expr_seach','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'expr_seach','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'expr_seach','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'express_search','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'expr_seach','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'express_search','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'expr_seach','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'express_search','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'expr_seach','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'express_search','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'expr_seach','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'express_search','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+ sql """ INSERT INTO t_map_count VALUES(1,
'expr_seach','consumer-un','17469174857s957ssf','page_l','36e44300d6c7433784852347b167ccdbd');"""
+
+ sql """ set parallel_pipeline_task_num=5; """
+
+ // test in old planner
+ sql """set enable_nereids_planner=false"""
+ order_qt_old_sql """ SELECT id, c_char, map('exp_sea', 1) as m FROM
t_map_count WHERE p1 = 'comr' AND p2 = 'ex' GROUP BY 1,2
+ union all
+ SELECT id, c_char, map('exp_seac', count(CASE WHEN
et = 'page_l' THEN uid END )) as m FROM t_map_count WHERE p1 = 'consumer-un'
AND p2 = '17469174857s957ssf' GROUP BY 1,2;"""
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]