Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](funcs) map struct construct funcs #39699

Merged
merged 4 commits into from
Aug 27, 2024
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: 1 addition & 0 deletions be/src/vec/functions/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ class IFunction : public std::enable_shared_from_this<IFunction>,
public:
String get_name() const 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) const override = 0;
Expand Down
12 changes: 6 additions & 6 deletions be/src/vec/functions/function_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,26 @@ class FunctionMap : public IFunction {
result_col_map_offsets.resize(input_rows_count);

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));
}
}

// insert value into map
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;
Expand Down
7 changes: 4 additions & 3 deletions be/src/vec/functions/function_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,22 @@ class FunctionStruct : public IFunction {
"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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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}

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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;"""


// test in nereids planner
sql """set enable_nereids_planner=true"""
sql """ set enable_fallback_to_original_planner=false"""
order_qt_nereid_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;"""
}
Loading