You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/07/09 04:39:20 UTC

[doris] 01/01: [tmpfix] expr compose and replace bug

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

morningman pushed a commit to branch dev-1.0.1-v20220709
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 3d1d8ebdce6edcb9b02d8598b830e3293b7b097d
Author: morningman <mo...@apache.org>
AuthorDate: Sat Jul 9 12:39:01 2022 +0800

    [tmpfix] expr compose and replace bug
---
 be/src/vec/exprs/vslot_ref.cpp                     |  5 +++--
 .../apache/doris/analysis/ExprSubstitutionMap.java | 23 +++++++++++++++++-----
 .../org/apache/doris/planner/HashJoinNode.java     |  2 +-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/be/src/vec/exprs/vslot_ref.cpp b/be/src/vec/exprs/vslot_ref.cpp
index 57038eb63f..8cbc56cb37 100644
--- a/be/src/vec/exprs/vslot_ref.cpp
+++ b/be/src/vec/exprs/vslot_ref.cpp
@@ -20,6 +20,7 @@
 #include <fmt/format.h>
 
 #include "runtime/descriptors.h"
+#include "util/stack_util.h"
 
 namespace doris::vectorized {
 using doris::Status;
@@ -59,7 +60,7 @@ Status VSlotRef::prepare(doris::RuntimeState* state, const doris::RowDescriptor&
 }
 
 Status VSlotRef::execute(VExprContext* context, Block* block, int* result_column_id) {
-    DCHECK_GE(_column_id, 0);
+    CHECK_GE(_column_id, 0) << ", " << debug_string() << ", " << get_stack_trace();
     *result_column_id = _column_id;
     return Status::OK();
 }
@@ -69,7 +70,7 @@ const std::string& VSlotRef::expr_name() const {
 }
 std::string VSlotRef::debug_string() const {
     std::stringstream out;
-    out << "SlotRef(slot_id=" << _slot_id << VExpr::debug_string() << ")";
+    out << "SlotRef(slot_id=" << _slot_id << VExpr::debug_string() << ") column id: " << _column_id << ", name: " << *_column_name << ", is nulable: " << _is_nullable;
     return out.str();
 }
 } // namespace doris::vectorized
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExprSubstitutionMap.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExprSubstitutionMap.java
index e0df525ce5..6fe94f8578 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExprSubstitutionMap.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExprSubstitutionMap.java
@@ -17,6 +17,8 @@
 
 package org.apache.doris.analysis;
 
+import org.apache.doris.common.AnalysisException;
+
 import java.util.List;
 import java.util.Objects;
 
@@ -189,7 +191,7 @@ public final class ExprSubstitutionMap {
      * f [A.id, B.id] [A.name, B.name] g [A.id, C.id] [A.age, C.age]
      * return: [A.id, C,id] [A.name, B.name] [A.age, C.age]
      */
-    public static ExprSubstitutionMap composeAndReplace(ExprSubstitutionMap f, ExprSubstitutionMap g) {
+    public static ExprSubstitutionMap composeAndReplace(ExprSubstitutionMap f, ExprSubstitutionMap g, Analyzer analyzer) throws AnalysisException {
         if (f == null && g == null) {
             return new ExprSubstitutionMap();
         }
@@ -200,11 +202,22 @@ public final class ExprSubstitutionMap {
             return f;
         }
         ExprSubstitutionMap result = new ExprSubstitutionMap();
-        result = ExprSubstitutionMap.combine(result, g);
+        // compose f and g
         for (int i = 0; i < g.size(); i++) {
-            // case a->b, b->c => a->c
-            if (f.mappingForRhsExpr(g.getLhs().get(i)) != null) {
-                result.getLhs().set(i, f.mappingForRhsExpr(g.getLhs().get(i)));
+            boolean findGMatch = false;
+            Expr gLhs = g.getLhs().get(i);
+            for (int j = 0; j < f.size(); j++) {
+                // case a->fn(b), b->c => a->fn(c)
+                Expr fRhs = f.getRhs().get(j);
+                if (fRhs.contains(gLhs)) {
+                    Expr newRhs = fRhs.trySubstitute(g, analyzer, false);
+                    result.put(f.getLhs().get(j), newRhs);
+                    findGMatch = true;
+                    break;
+                }
+            }
+            if (!findGMatch) {
+                result.put(g.getLhs().get(i), g.getRhs().get(i));
             }
         }
         // add remaining f
diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java
index 16e82b644f..f0c20ebec1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java
@@ -441,7 +441,7 @@ public class HashJoinNode extends PlanNode {
             }
         }
         // 4. change the outputSmap
-        outputSmap = ExprSubstitutionMap.composeAndReplace(outputSmap, srcTblRefToOutputTupleSmap);
+        outputSmap = ExprSubstitutionMap.composeAndReplace(outputSmap, srcTblRefToOutputTupleSmap, analyzer);
     }
 
     private void replaceOutputSmapForOuterJoin() {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org