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

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


The following commit(s) were added to refs/heads/master by this push:
     new dddacd120d [fix](planner) Fix  inconsistent nullability between 
outputTuple and groupByExpr when executing agg query (#11361)
dddacd120d is described below

commit dddacd120d70217d57580d1c7fd900c89a32c332
Author: Kikyou1997 <[email protected]>
AuthorDate: Mon Aug 1 22:57:51 2022 +0800

    [fix](planner) Fix  inconsistent nullability between outputTuple and 
groupByExpr when executing agg query (#11361)
---
 .../org/apache/doris/analysis/AggregateInfo.java   | 33 ++++++++
 .../data/query/aggregate/aggregate_output_null.out |  4 +
 .../query/aggregate/aggregate_output_null.groovy   | 90 ++++++++++++++++++++++
 3 files changed, 127 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfo.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfo.java
index cd38b4ee52..1ddab852ee 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfo.java
@@ -475,6 +475,39 @@ public final class AggregateInfo extends AggregateInfoBase 
{
         if (secondPhaseDistinctAggInfo != null) {
             secondPhaseDistinctAggInfo.substitute(smap, analyzer);
         }
+
+
+        // About why:
+        // The outputTuple of the first phase aggregate info is generated at 
analysis phase of SelectStmt,
+        // and the SlotDescriptor of output tuple of this agg info will refer 
to the origin column of the
+        // table in the same query block.
+        //
+        // However, if the child node is a HashJoinNode with outerJoin type, 
the nullability of the SlotDescriptor
+        // might be changed, those changed SlotDescriptor is referred by a 
SlotRef, and this SlotRef will be added
+        // to the outputSmap of the HashJoinNode.
+        //
+        // In BE execution, the SlotDescriptor which referred by output and 
groupBy should have the same nullability,
+        // So we need the update SlotDescriptor of output tuple.
+        //
+        // About how:
+        // Since the outputTuple of agg info is simply create a SlotRef and 
SlotDescriptor for each expr in aggregate
+        // expr and groupBy expr, so we could handle this as this way.
+        for (SlotDescriptor slotDesc : getOutputTupleDesc().getSlots()) {
+            List<Expr> exprList = slotDesc.getSourceExprs();
+            if (exprList.size() > 1) {
+                continue;
+            }
+            Expr expr = exprList.get(0);
+            if (!(expr instanceof SlotRef)) {
+                continue;
+            }
+            SlotRef slotRef = (SlotRef) expr;
+            Expr right = smap.get(slotRef);
+            if (right == null) {
+                continue;
+            }
+            slotDesc.setIsNullable(right.isNullable());
+        }
     }
 
     /**
diff --git a/regression-test/data/query/aggregate/aggregate_output_null.out 
b/regression-test/data/query/aggregate/aggregate_output_null.out
new file mode 100644
index 0000000000..8b00b073ec
--- /dev/null
+++ b/regression-test/data/query/aggregate/aggregate_output_null.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+\N     test    10
+
diff --git 
a/regression-test/suites/query/aggregate/aggregate_output_null.groovy 
b/regression-test/suites/query/aggregate/aggregate_output_null.groovy
new file mode 100644
index 0000000000..97cbd6da39
--- /dev/null
+++ b/regression-test/suites/query/aggregate/aggregate_output_null.groovy
@@ -0,0 +1,90 @@
+/*
+ * 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_output_null") {
+    sql "DROP TABLE IF EXISTS t1;"
+    sql """
+        CREATE TABLE `t1`
+        (
+           
+            `a`                varchar(255) NULL ,
+            `b`                varchar(255) NULL ,
+            `c`                varchar(255) NULL ,
+            `d`                int(11) NULL 
+        ) ENGINE=OLAP
+        DISTRIBUTED BY HASH(`c`) BUCKETS 3
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1"
+        );
+    """
+    sql """DROP TABLE IF EXISTS t2;"""
+    sql """
+        CREATE TABLE `t2`
+        (
+            `e` varchar(11) NOT NULL ,
+            `a`      varchar(6)  NOT NULL 
+        ) ENGINE=OLAP
+        UNIQUE KEY(`e`, `a`)
+        DISTRIBUTED BY HASH(`e`) BUCKETS 1
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1"
+        );
+    """
+
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+    sql """INSERT INTO t1 VALUES("test", "test", "test",1 );"""
+
+    sql """
+        INSERT INTO t2 (e,a) VALUES
+           ('','VZL8y'),
+           ('18hurd','EH'),
+           ('3','54m'),
+           ('6KldLAISE6N','wI5WN'),
+           ('AswEmp','1q'),
+           ('BmT4OGW','O'),
+           ('P6zKDh','pw'),
+           ('iqQ0NzI','Av6BE'),
+           ('oXtDwu','BMIG3U'),
+           ('z178NhOZ','b');
+    """
+
+    qt_select """
+        SELECT
+            t2.a,
+            t1.c,
+            sum(d)
+        FROM
+            t1
+            LEFT JOIN t2 ON t2.e = t1.b
+        GROUP BY
+            t2.a,
+            t1.c;
+    """
+
+    sql "DROP TABLE t1"
+    sql "DROP TABLE t2"
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to