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

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

commit be22ca0de7e512df5dc443b99ed6df63635f9dfe
Author: Pengfei Zhan <dethr...@gmail.com>
AuthorDate: Mon Oct 2 17:48:57 2023 +0800

    KYLIN-5839 Block agg-push-down for non-equal-join
    
    KYLIN-5382 only deals with the equal-join conditions and gives the
    corresponding test cases.
    KYLIN-5831 fixed the problem where non-equiv-join conditions were
    incorrectly converted to equivalent conditions. Due to the lack of test
    cases, a regression bug occurs in ContextUtil.isJoinFromSameContext.
    
    The related non-equiv-join sql is as follows.
    If you want a corresponding equal-join sql, just remove the condition
    content `or (t2.fcol_10 is null and t5.fcol_17 is null)`.
    
    ```sql
    select t2.fcol_7 fcol_7, count(distinct t2.fcol_6) fcol_6
    from (select t1.company_code fcol_6, t1.type_name fcol_7,
              case when t1.created_date = t0.fcol_1 then 'TRUE'
              else 'FALSE' end fcol_10
          from ( select company_code, created_date, type_name
                from "DEFAULT"."TEST_AGG_PUSH_DOWN" ) t1
                join ( select company_code, max(created_date) fcol_1
                       from "DEFAULT"."TEST_AGG_PUSH_DOWN"
                       group by company_code
                ) t0 on t1.company_code = t0.company_code
        ) t2 join ( select 'TRUE' fcol_17 ) t5
        on  t2.fcol_10 = t5.fcol_17 or (t2.fcol_10 is null and t5.fcol_17 is 
null)
    group by t2.fcol_7
    ```
---
 .../apache/kylin/query/relnode/ContextUtil.java    | 24 ++++++++++++++--------
 .../kylin/query/relnode/KapNonEquiJoinRel.java     |  3 +++
 2 files changed, 19 insertions(+), 8 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 d08d0d073d..4a063cf82f 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
@@ -36,15 +36,14 @@ import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.rex.RexSlot;
 import org.apache.calcite.sql.fun.SqlCountAggFunction;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.kylin.guava30.shaded.common.collect.Lists;
+import org.apache.kylin.guava30.shaded.common.collect.Sets;
 import org.apache.kylin.common.QueryContext;
 import org.apache.kylin.metadata.model.TblColRef;
 import org.apache.kylin.query.util.RexUtils;
 import org.apache.kylin.util.CalciteSystemProperty;
 import org.slf4j.Logger;
 
-import org.apache.kylin.guava30.shaded.common.collect.Lists;
-import org.apache.kylin.guava30.shaded.common.collect.Sets;
-
 public class ContextUtil {
     private ContextUtil() {
     }
@@ -203,12 +202,21 @@ public class ContextUtil {
             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);
+            if (joinRel instanceof KapJoinRel) {
+                ((KapJoinRel) joinRel).leftKeys.forEach(leftKey -> {
+                    RexNode leftCol = ((KapProjectRel) 
potentialSubRel).getProjects().get(leftKey);
+                    if (leftCol instanceof RexCall) {
+                        indexOfInputCols.add(leftKey);
+                    }
+                });
+            } else {
+                // non-equiv-join rel: treat the left and right subtrees as a 
context,
+                // and refuse to push agg down.
+                KapNonEquiJoinRel nonEquivJoinRel = (KapNonEquiJoinRel) 
joinRel;
+                if (!nonEquivJoinRel.isScd2Rel()) {
+                    return false;
                 }
-            });
+            }
         }
         return derivedFromSameContext(indexOfInputCols, potentialSubRel, 
subContext, hasCountConstant);
     }
diff --git 
a/src/query-common/src/main/java/org/apache/kylin/query/relnode/KapNonEquiJoinRel.java
 
b/src/query-common/src/main/java/org/apache/kylin/query/relnode/KapNonEquiJoinRel.java
index d3cfda0c2c..0b9840cc1b 100644
--- 
a/src/query-common/src/main/java/org/apache/kylin/query/relnode/KapNonEquiJoinRel.java
+++ 
b/src/query-common/src/main/java/org/apache/kylin/query/relnode/KapNonEquiJoinRel.java
@@ -63,6 +63,8 @@ import org.apache.kylin.query.util.ICutContextStrategy;
 import org.apache.kylin.query.util.RexToTblColRefTranslator;
 import org.apache.kylin.query.util.RexUtils;
 
+import lombok.Getter;
+
 public class KapNonEquiJoinRel extends EnumerableThetaJoin implements KapRel {
 
     private OLAPContext context;
@@ -75,6 +77,7 @@ public class KapNonEquiJoinRel extends EnumerableThetaJoin 
implements KapRel {
     // record left input size before rewrite for runtime join expression 
parsing
     private int leftInputSizeBeforeRewrite = -1;
 
+    @Getter
     private final boolean isScd2Rel;
 
     public KapNonEquiJoinRel(RelOptCluster cluster, RelTraitSet traits, 
RelNode left, RelNode right, RexNode condition,

Reply via email to