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

yiguolei pushed a commit to branch branch-1.1-lts
in repository https://gitbox.apache.org/repos/asf/doris.git


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

commit 753413982631c89749d98c9be1718fd0363ff3b9
Author: starocean999 <[email protected]>
AuthorDate: Tue Nov 8 16:47:19 2022 +0800

    [fix](planner) Fix inconsistent nullability between outputTuple and 
groupByExpr when executing agg query (#14050)
    
    * [fix](planner) Fix inconsistent nullability between outputTuple and 
groupByExpr when executing agg query
    
    * [fix](repeat)remove unmaterialized expr from repeat node
---
 .../org/apache/doris/analysis/AggregateInfo.java   | 24 ++++++++++++++++++++++
 .../org/apache/doris/analysis/GroupingInfo.java    | 22 ++++++++++++++++++++
 2 files changed, 46 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 612801f38c..e93b0ad748 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
@@ -441,6 +441,30 @@ 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 srcExpr = exprList.get(0).substitute(smap);
+            slotDesc.setIsNullable(srcExpr.isNullable() || 
slotDesc.getIsNullable());
+        }
     }
 
     /**
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
index b7ba987cc6..c68df0784b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
@@ -89,7 +89,29 @@ public class GroupingInfo {
     }
 
     public void substitutePreRepeatExprs(ExprSubstitutionMap smap, Analyzer 
analyzer) {
+        ArrayList<Expr> originalPreRepeatExprs = new 
ArrayList<>(preRepeatExprs);
         preRepeatExprs = Expr.substituteList(preRepeatExprs, smap, analyzer, 
true);
+
+        // remove unmaterialized slotRef from preRepeatExprs
+        ArrayList<Expr> materializedPreRepeatExprs = new ArrayList<>();
+        ArrayList<Expr> unMaterializedSlotRefs = new ArrayList<>();
+        for (int i = 0; i < preRepeatExprs.size(); ++i) {
+            Expr expr = preRepeatExprs.get(i);
+            if (expr instanceof SlotRef && !((SlotRef) 
expr).getDesc().isMaterialized()) {
+                unMaterializedSlotRefs.add(originalPreRepeatExprs.get(i));
+            } else {
+                materializedPreRepeatExprs.add(expr);
+            }
+        }
+        preRepeatExprs = materializedPreRepeatExprs;
+
+        // set slotRef unmaterialized in outputTupleSmap
+        for (Expr expr : unMaterializedSlotRefs) {
+            Expr rExpr = outputTupleSmap.get(expr);
+            if (rExpr instanceof SlotRef) {
+                ((SlotRef) rExpr).getDesc().setIsMaterialized(false);
+            }
+        }
     }
 
     // generate virtual slots for grouping or grouping_id functions


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

Reply via email to