You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by xx...@apache.org on 2022/12/29 01:39:20 UTC

[kylin] branch kylin5 updated: KYLIN-5382 Block the agg pushdown when there is a non RexCall in the project

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

xxyu pushed a commit to branch kylin5
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/kylin5 by this push:
     new 651db7f0fe KYLIN-5382 Block the agg pushdown when there is a non RexCall in the project
651db7f0fe is described below

commit 651db7f0fe5b9354f8c3f6bd1cafa081f907e286
Author: Wang Hui <wa...@users.noreply.github.com>
AuthorDate: Mon Oct 31 14:12:05 2022 +0800

    KYLIN-5382 Block the agg pushdown when there is a non RexCall in the project
    
    Co-authored-by: hui.wang <hu...@kyligence.io>
---
 .../apache/kylin/query/relnode/ContextUtil.java    | 65 +++++++++++++---------
 1 file changed, 38 insertions(+), 27 deletions(-)

diff --git a/src/query-common/src/main/java/org/apache/kylin/query/relnode/ContextUtil.java b/src/query-common/src/main/java/org/apache/kylin/query/relnode/ContextUtil.java
index a2f1026c30..766335ce7a 100644
--- a/src/query-common/src/main/java/org/apache/kylin/query/relnode/ContextUtil.java
+++ b/src/query-common/src/main/java/org/apache/kylin/query/relnode/ContextUtil.java
@@ -50,8 +50,6 @@ public class ContextUtil {
 
     /**
      * used for collect a rel node's all subContext, which contain the context of itself
-     *
-     * @param subRel
      */
     public static Set<OLAPContext> collectSubContext(RelNode subRel) {
         Set<OLAPContext> subContexts = Sets.newHashSet();
@@ -117,11 +115,6 @@ public class ContextUtil {
         }
     }
 
-    public static void resetContext(KapRel kapRel) {
-        kapRel.setContext(null);
-
-    }
-
     private static boolean derivedFromSameContext(Collection<Integer> indexOfInputCols, RelNode currentNode,
             OLAPContext subContext, boolean hasCountConstant) {
         if (currentNode instanceof KapAggregateRel) {
@@ -188,33 +181,51 @@ public class ContextUtil {
         int maxIndex = Collections.max(indexOfInputCols);
         int leftLength = joinRel.getLeft().getRowType().getFieldList().size();
         if (maxIndex < leftLength) {
-            KapRel potentialSubRel = (KapRel) joinRel.getLeft();
-            if (subContext == potentialSubRel.getContext()) {
-                return true;
-            }
-            if (potentialSubRel.getContext() != null) {
-                return false;
-            }
-            return derivedFromSameContext(indexOfInputCols, potentialSubRel, subContext, hasCountConstant);
+            return isLeftJoinFromSameContext(indexOfInputCols, joinRel, subContext, hasCountConstant);
         }
         int minIndex = Collections.min(indexOfInputCols);
         if (minIndex >= leftLength) {
-            KapRel potentialSubRel = (KapRel) joinRel.getRight();
-            if (subContext == potentialSubRel.getContext()) {
-                return true;
-            }
-            if (potentialSubRel.getContext() != null) {
-                return false;
-            }
-            Set<Integer> indexOfInputRel = Sets.newHashSet();
-            for (Integer indexOfInputCol : indexOfInputCols) {
-                indexOfInputRel.add(indexOfInputCol - leftLength);
-            }
-            return derivedFromSameContext(indexOfInputRel, potentialSubRel, subContext, hasCountConstant);
+            return isRightJoinFromSameContext(indexOfInputCols, joinRel, subContext, hasCountConstant, leftLength);
         }
         return false;
     }
 
+    private static boolean isLeftJoinFromSameContext(Collection<Integer> indexOfInputCols, Join joinRel,
+            OLAPContext subContext, boolean hasCountConstant) {
+        KapRel potentialSubRel = (KapRel) joinRel.getLeft();
+        if (subContext == potentialSubRel.getContext()) {
+            return true;
+        }
+        if (potentialSubRel.getContext() != null) {
+            return false;
+        }
+        if (potentialSubRel instanceof KapProjectRel) {
+            ((KapJoinRel) joinRel).leftKeys.forEach(leftKey -> {
+                RexNode leftCol = ((KapProjectRel) potentialSubRel).getProjects().get(leftKey);
+                if (leftCol instanceof RexCall) {
+                    indexOfInputCols.add(leftKey);
+                }
+            });
+        }
+        return derivedFromSameContext(indexOfInputCols, potentialSubRel, subContext, hasCountConstant);
+    }
+
+    private static boolean isRightJoinFromSameContext(Collection<Integer> indexOfInputCols, Join joinRel,
+            OLAPContext subContext, boolean hasCountConstant, int leftLength) {
+        KapRel potentialSubRel = (KapRel) joinRel.getRight();
+        if (subContext == potentialSubRel.getContext()) {
+            return true;
+        }
+        if (potentialSubRel.getContext() != null) {
+            return false;
+        }
+        Set<Integer> indexOfInputRel = Sets.newHashSet();
+        for (Integer indexOfInputCol : indexOfInputCols) {
+            indexOfInputRel.add(indexOfInputCol - leftLength);
+        }
+        return derivedFromSameContext(indexOfInputRel, potentialSubRel, subContext, hasCountConstant);
+    }
+
     private static boolean areSubJoinRelsSameType(RelNode kapRel, OLAPContext subContext, JoinRelType expectedJoinType,
             Class<?> joinCondClz) {
         OLAPContext ctx = ((KapRel) kapRel).getContext();