You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by li...@apache.org on 2022/05/25 08:44:02 UTC

[incubator-doris] branch master updated: [fix] group by with two NULL rows after left join (#9688)

This is an automated email from the ASF dual-hosted git repository.

lihaopeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 2725127421 [fix] group by with two NULL rows after left join (#9688)
2725127421 is described below

commit 272512742196c8d5d3d8225988d8f26d7851c58d
Author: camby <10...@qq.com>
AuthorDate: Wed May 25 16:43:55 2022 +0800

    [fix] group by with two NULL rows after left join (#9688)
    
    Co-authored-by: cambyzju <zh...@baidu.com>
---
 be/src/vec/columns/column_nullable.cpp             |  5 +-
 .../query/aggregate/aggregate_groupby_null.out     |  7 +++
 .../query/aggregate/aggregate_groupby_null.groovy  | 58 ++++++++++++++++++++++
 3 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/be/src/vec/columns/column_nullable.cpp b/be/src/vec/columns/column_nullable.cpp
index f7cf9e9d3e..215ced2383 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/data/query/aggregate/aggregate_groupby_null.out b/regression-test/data/query/aggregate/aggregate_groupby_null.out
new file mode 100644
index 0000000000..9c44613df2
--- /dev/null
+++ b/regression-test/data/query/aggregate/aggregate_groupby_null.out
@@ -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
+
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: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org