From f915ba4f139beae7a5e6bdb8dbd86342adfe1673 Mon Sep 17 00:00:00 2001 From: cambyzju Date: Mon, 15 Aug 2022 21:54:36 +0800 Subject: [PATCH] fix issue 7288 in vectorized engine --- .../aggregate_function_group_concat.h | 12 ++++- .../test_group_concat_new_tbl.out | 7 +++ .../test_group_concat_new_tbl.groovy | 51 +++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 regression-test/data/query/group_concat/test_group_concat_new_tbl.out create mode 100644 regression-test/suites/query/group_concat/test_group_concat_new_tbl.groovy diff --git a/be/src/vec/aggregate_functions/aggregate_function_group_concat.h b/be/src/vec/aggregate_functions/aggregate_function_group_concat.h index 33c83fc7b00b99..a4b682c1128ef8 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_group_concat.h +++ b/be/src/vec/aggregate_functions/aggregate_function_group_concat.h @@ -59,6 +59,7 @@ struct AggregateFunctionGroupConcatData { } std::string get() const { return data; } + bool is_null() const { return !inited; } void write(BufferWritable& buf) const { write_binary(data, buf); @@ -132,8 +133,15 @@ class AggregateFunctionGroupConcat final } void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { - std::string result = this->data(place).get(); - static_cast(to).insert_data(result.c_str(), result.length()); + bool is_null = this->data(place).is_null(); + std::string result = is_null ? "" : this->data(place).get(); + if (to.is_nullable()) { + static_cast(to).get_null_map_data().push_back(is_null); + static_cast(to).get_nested_column().insert_data(result.c_str(), + result.length()); + } else { + static_cast(to).insert_data(result.c_str(), result.length()); + } } }; diff --git a/regression-test/data/query/group_concat/test_group_concat_new_tbl.out b/regression-test/data/query/group_concat/test_group_concat_new_tbl.out new file mode 100644 index 00000000000000..a669fedada5a69 --- /dev/null +++ b/regression-test/data/query/group_concat/test_group_concat_new_tbl.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +1 \N + +-- !select -- +1 \N + diff --git a/regression-test/suites/query/group_concat/test_group_concat_new_tbl.groovy b/regression-test/suites/query/group_concat/test_group_concat_new_tbl.groovy new file mode 100644 index 00000000000000..914460fe740831 --- /dev/null +++ b/regression-test/suites/query/group_concat/test_group_concat_new_tbl.groovy @@ -0,0 +1,51 @@ +// 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_group_concat_new_tbl", "issue_7288") { + def leftTableName = "group_concat_i7288_left" + def rightTableName = "group_concat_i7288_right" + sql "DROP TABLE IF EXISTS ${leftTableName}" + sql """ + CREATE TABLE IF NOT EXISTS ${leftTableName} ( + k1 int, + no varchar(10) NOT NULL + ) + DISTRIBUTED BY HASH(k1) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ) + """ + sql "INSERT INTO ${leftTableName} values(1,'test')" + + sql "DROP TABLE IF EXISTS ${rightTableName}" + sql """ + CREATE TABLE IF NOT EXISTS ${rightTableName} ( + k1 int, + no varchar(10) NOT NULL + ) + DISTRIBUTED BY HASH(k1) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ) + """ + + sql "set enable_vectorized_engine=true" + qt_select(""" select l.k1, group_concat(r.no) from ${leftTableName} l left join ${rightTableName} r on l.k1=r.k1 group by l.k1; """); + + sql "set enable_vectorized_engine=false" + qt_select(""" select l.k1, group_concat(r.no) from ${leftTableName} l left join ${rightTableName} r on l.k1=r.k1 group by l.k1; """); +} \ No newline at end of file