Skip to content

Commit

Permalink
[fix] group by with two NULL rows after left join (apache#9688)
Browse files Browse the repository at this point in the history
Co-authored-by: cambyzju <[email protected]>
  • Loading branch information
2 people authored and yinzhijian committed May 26, 2022
1 parent d66f2ce commit cffb433
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
5 changes: 4 additions & 1 deletion be/src/vec/columns/column_nullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !groupby_null --
\N 3

-- !groupby_null --
\N 3

Original file line number Diff line number Diff line change
@@ -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 """
}

0 comments on commit cffb433

Please sign in to comment.