This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch dev-1.0.1 in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
commit 5a1d1faba9964c8e8595628293d1278031eca079 Author: camby <[email protected]> AuthorDate: Wed May 25 16:43:55 2022 +0800 [fix] group by with two NULL rows after left join (#9688) Co-authored-by: cambyzju <[email protected]> --- be/src/vec/columns/column_nullable.cpp | 5 +- .../query/aggregate/aggregate_groupby_null.groovy | 58 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/be/src/vec/columns/column_nullable.cpp b/be/src/vec/columns/column_nullable.cpp index 69634effb4..58f81fdf5e 100644 --- a/be/src/vec/columns/column_nullable.cpp +++ b/be/src/vec/columns/column_nullable.cpp @@ -102,7 +102,10 @@ StringRef ColumnNullable::serialize_value_into_arena(size_t n, Arena& arena, static constexpr auto s = sizeof(arr[0]); auto pos = arena.alloc_continue(s, begin); - memcpy(pos, &arr[n], s); + // Value of `NULL` may be 1 or JOIN_NULL_HINT, we serialize both to 1. + // Because we need same key for both `NULL` values while processing `group by`. + UInt8* val = reinterpret_cast<UInt8*>(pos); + *val = (arr[n] ? 1 : 0); if (arr[n]) return StringRef(pos, s); diff --git a/regression-test/suites/query/aggregate/aggregate_groupby_null.groovy b/regression-test/suites/query/aggregate/aggregate_groupby_null.groovy new file mode 100644 index 0000000000..dc3742c5fe --- /dev/null +++ b/regression-test/suites/query/aggregate/aggregate_groupby_null.groovy @@ -0,0 +1,58 @@ +// 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("aggregate_groupby_null") { + def leftTable = "agg_groupby_null_left" + sql """ DROP TABLE IF EXISTS ${leftTable} """ + sql """ + CREATE TABLE IF NOT EXISTS ${leftTable} ( + id INT NULL, + device_id STRING NULL + ) + UNIQUE KEY(id) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ) + """ + sql """ INSERT INTO ${leftTable} VALUES (1,'1'),(2,'2'),(3,'3'),(4,'4') """ + + def rightTable = "agg_groupby_null_right" + sql """ DROP TABLE IF EXISTS ${rightTable} """ + sql """ + CREATE TABLE IF NOT EXISTS ${rightTable} ( + id INT NULL, + device_name STRING NULL + ) + UNIQUE KEY(id) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ) + """ + sql """ INSERT INTO ${rightTable} VALUES (1,'name'),(3,null) """ + + sql """ set enable_vectorized_engine=false """ + qt_groupby_null """ SELECT rt.device_name, COUNT(${leftTable}.id) FROM ${leftTable} + LEFT JOIN ${rightTable} rt ON ${leftTable}.id = rt.id + WHERE rt.device_name is NULL group by rt.device_name """ + + sql """ set enable_vectorized_engine=true """ + qt_groupby_null """ SELECT rt.device_name, COUNT(${leftTable}.id) FROM ${leftTable} + LEFT JOIN ${rightTable} rt ON ${leftTable}.id = rt.id + WHERE rt.device_name is NULL group by rt.device_name """ +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
