You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2020/05/22 10:41:53 UTC

[kylin] branch master updated: KYLIN-4464 Not apply SortProjectTransposeRule when window func in projection

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

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


The following commit(s) were added to refs/heads/master by this push:
     new c5573dc  KYLIN-4464 Not apply SortProjectTransposeRule when window func in projection
c5573dc is described below

commit c5573dc9be7ad86b3a8c71bc4a17092594bdf8f9
Author: chao long <wa...@qq.com>
AuthorDate: Tue Apr 21 11:52:18 2020 +0800

    KYLIN-4464 Not apply SortProjectTransposeRule when window func in projection
---
 .../optrule/KylinSortProjectTransposeRule.java     | 47 ++++++++++++++++++++++
 .../apache/kylin/query/relnode/OLAPTableScan.java  |  6 +++
 2 files changed, 53 insertions(+)

diff --git a/query/src/main/java/org/apache/kylin/query/optrule/KylinSortProjectTransposeRule.java b/query/src/main/java/org/apache/kylin/query/optrule/KylinSortProjectTransposeRule.java
new file mode 100644
index 0000000..7f2abd5
--- /dev/null
+++ b/query/src/main/java/org/apache/kylin/query/optrule/KylinSortProjectTransposeRule.java
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+package org.apache.kylin.query.optrule;
+
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rel.core.Sort;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.rules.SortProjectTransposeRule;
+import org.apache.calcite.rex.RexOver;
+import org.apache.calcite.tools.RelBuilderFactory;
+
+public class KylinSortProjectTransposeRule extends SortProjectTransposeRule {
+    public static final KylinSortProjectTransposeRule INSTANCE =
+            new KylinSortProjectTransposeRule(Sort.class, LogicalProject.class,
+                    RelFactories.LOGICAL_BUILDER, null);
+
+    private KylinSortProjectTransposeRule(
+            Class<? extends Sort> sortClass,
+            Class<? extends Project> projectClass,
+            RelBuilderFactory relBuilderFactory, String description) {
+        super(
+                operand(sortClass,
+                        operand(projectClass, null, KylinSortProjectTransposeRule::noWindowFunc, any())),
+                relBuilderFactory, description);
+    }
+
+    private static boolean noWindowFunc(Project project) {
+        return !RexOver.containsOver(project.getProjects(), null);
+    }
+}
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
index f0d5b5c..98ff447 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
@@ -61,6 +61,7 @@ import org.apache.calcite.rel.rules.JoinUnionTransposeRule;
 import org.apache.calcite.rel.rules.ReduceExpressionsRule;
 import org.apache.calcite.rel.rules.SemiJoinRule;
 import org.apache.calcite.rel.rules.SortJoinTransposeRule;
+import org.apache.calcite.rel.rules.SortProjectTransposeRule;
 import org.apache.calcite.rel.rules.SortUnionTransposeRule;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
@@ -75,6 +76,7 @@ import org.apache.kylin.metadata.model.TableRef;
 import org.apache.kylin.metadata.model.TblColRef;
 import org.apache.kylin.query.enumerator.DictionaryEnumerator;
 import org.apache.kylin.query.optrule.AggregateProjectReduceRule;
+import org.apache.kylin.query.optrule.KylinSortProjectTransposeRule;
 import org.apache.kylin.query.optrule.OLAPAggregateRule;
 import org.apache.kylin.query.optrule.OLAPFilterRule;
 import org.apache.kylin.query.optrule.OLAPJoinRule;
@@ -211,6 +213,10 @@ public class OLAPTableScan extends TableScan implements OLAPRel, EnumerableRel {
 
         // see Dec 26th email @ http://mail-archives.apache.org/mod_mbox/calcite-dev/201412.mbox/browser
         planner.removeRule(ExpandConversionRule.INSTANCE);
+
+        // KYLIN-4464 do not pushdown sort when there is a window function in projection
+        planner.removeRule(SortProjectTransposeRule.INSTANCE);
+        planner.addRule(KylinSortProjectTransposeRule.INSTANCE);
     }
 
     protected void addRules(final RelOptPlanner planner, List<String> rules) {