You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kylin.apache.org by GitBox <gi...@apache.org> on 2019/01/07 02:19:35 UTC

[GitHub] shaofengshi closed pull request #397: KYLIN-3722 Disable limit push down for complex query

shaofengshi closed pull request #397: KYLIN-3722 Disable limit push down for complex query
URL: https://github.com/apache/kylin/pull/397
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
index 018552caf1..c98cb90bad 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
@@ -314,8 +314,7 @@ public String getMetastoreBigCellHdfsDirectory() {
     public String getReadHdfsWorkingDirectory() {
         if (StringUtils.isNotEmpty(getHBaseClusterFs())) {
             Path workingDir = new Path(getHdfsWorkingDirectory());
-            return new Path(getHBaseClusterFs(), Path.getPathWithoutSchemeAndAuthority(workingDir)).toString()
-                    + "/";
+            return new Path(getHBaseClusterFs(), Path.getPathWithoutSchemeAndAuthority(workingDir)).toString() + "/";
         }
 
         return getHdfsWorkingDirectory();
@@ -1908,12 +1907,13 @@ public boolean isJsonAlwaysSmallCell() {
     }
 
     public int getSmallCellMetadataWarningThreshold() {
-        return Integer.parseInt(getOptional("kylin.metadata.jdbc.small-cell-meta-size-warning-threshold",
-                String.valueOf(100 << 20))); //100mb
+        return Integer.parseInt(
+                getOptional("kylin.metadata.jdbc.small-cell-meta-size-warning-threshold", String.valueOf(100 << 20))); //100mb
     }
 
     public int getSmallCellMetadataErrorThreshold() {
-        return Integer.parseInt(getOptional("kylin.metadata.jdbc.small-cell-meta-size-error-threshold", String.valueOf(1 << 30))); // 1gb
+        return Integer.parseInt(
+                getOptional("kylin.metadata.jdbc.small-cell-meta-size-error-threshold", String.valueOf(1 << 30))); // 1gb
     }
 
     public int getJdbcResourceStoreMaxCellSize() {
@@ -1923,4 +1923,8 @@ public int getJdbcResourceStoreMaxCellSize() {
     public String getJdbcSourceAdaptor() {
         return getOptional("kylin.source.jdbc.adaptor");
     }
+
+    public boolean isLimitPushDownEnabled() {
+        return Boolean.parseBoolean(getOptional("kylin.storage.limit-push-down-enable", TRUE));
+    }
 }
diff --git a/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java b/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java
index 4fdc68e4ff..1e7bde4f02 100644
--- a/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java
+++ b/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java
@@ -282,8 +282,9 @@ public void testPreciselyDistinctCountQuery() throws Exception {
     @Test
     public void testPreciselyDistinctCountRollupQuery() throws Exception {
         // the "inner" test cube uses "SegmentAppendTrieDictBuilder" which doesn't support rollup.
-        if("left".equalsIgnoreCase(joinType)) {
-            execAndCompQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_distinct_precisely_rollup", null, true);
+        if ("left".equalsIgnoreCase(joinType)) {
+            execAndCompQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_distinct_precisely_rollup", null,
+                    true);
         }
     }
 
@@ -373,13 +374,18 @@ public void testLimitEnabled() throws Exception {
                 new File(getQueryFolderPrefix() + "src/test/resources/query/sql_limit"), ".sql");
         for (File sqlFile : sqlFiles) {
             runSQL(sqlFile, false, false);
-            assertTrue(checkFinalPushDownLimit());
+            if (sqlFile.getAbsolutePath().contains("query06.sql")) {
+                assertTrue(!checkFinalPushDownLimit());
+            } else {
+                assertTrue(checkFinalPushDownLimit());
+            }
         }
     }
 
     @Test
     public void testLimitCorrectness() throws Exception {
         this.execLimitAndValidate(getQueryFolderPrefix() + "src/test/resources/query/sql");
+
     }
 
     @Test
@@ -463,8 +469,6 @@ public void testValues() throws Exception {
         execAndCompQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_values", null, true);
     }
 
-
-
     @Test
     public void testPlan() throws Exception {
         String originProp = System.getProperty("calcite.debug");
@@ -473,5 +477,4 @@ public void testPlan() throws Exception {
         if (originProp == null || "false".equals(originProp))
             System.setProperty("calcite.debug", "false");
     }
-}
-                                                  
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/kylin-it/src/test/resources/query/sql_limit/query06.sql b/kylin-it/src/test/resources/query/sql_limit/query06.sql
new file mode 100644
index 0000000000..353fb60845
--- /dev/null
+++ b/kylin-it/src/test/resources/query/sql_limit/query06.sql
@@ -0,0 +1,26 @@
+--
+-- 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.
+--
+
+SELECT sum(price)
+FROM test_kylin_fact
+WHERE CAL_DT >= '2012-02-16' and CAL_DT <= '2012-03-16' and LEAF_CATEG_ID in
+(
+  SELECT DISTINCT LEAF_CATEG_ID
+  FROM TEST_CATEGORY_GROUPINGS
+  WHERE META_CATEG_NAME is not null
+) limit 10
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
index 4daaaabd27..340967cc04 100755
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
@@ -135,6 +135,7 @@ public OLAPContext(int seq) {
     public boolean hasWindow = false;
     public boolean groupByExpression = false; // checkout if group by column has operator
     public boolean afterOuterAggregate = false;
+    public boolean disableLimitPushdown = !KylinConfig.getInstanceFromEnv().isLimitPushDownEnabled();
 
     // cube metadata
     public IRealization realization;
@@ -293,6 +294,7 @@ public void unfixModel() {
         }
         fixedModel = false;
     }
+
     public void bindVariable(DataContext dataContext) {
         bindVariable(this.filter, dataContext);
     }
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java
index 7ec489b708..1d0654c563 100755
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java
@@ -82,7 +82,8 @@ public void implementOLAP(OLAPImplementor implementor) {
         // ignore limit after having clause
         // ignore limit after another limit, e.g. select A, count(*) from (select A,B from fact group by A,B limit 100) limit 10
         // ignore limit after outer aggregate, e.g. select count(1) from (select A,B from fact group by A,B ) limit 10
-        if (!context.afterHavingClauseFilter && !context.afterLimit && !context.afterOuterAggregate) {
+        if (!context.afterHavingClauseFilter && !context.afterLimit && !context.afterOuterAggregate
+                && !context.disableLimitPushdown) {
             Number limitValue = (Number) (((RexLiteral) localFetch).getValue());
             int limit = limitValue.intValue();
             this.context.storageContext.setLimit(limit);
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPRel.java
index 95f669345d..a10ba253c3 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPRel.java
@@ -106,6 +106,10 @@ public void freeContext() {
 
         public void allocateContext() {
             OLAPContext context = new OLAPContext(ctxSeq++);
+            if (!ctxStack.isEmpty()) {
+                ctxStack.peek().disableLimitPushdown = true;
+                context.disableLimitPushdown = true;
+            }
             ctxStack.push(context);
             OLAPContext.registerContext(context);
             setNewOLAPContextRequired(false);
@@ -224,8 +228,9 @@ public EnumerableRel createEnumerable(OLAPRel parent) {
         }
 
         @Override
-        public EnumerableRel.Result visitChild(EnumerableRel parent, int ordinal, EnumerableRel child, EnumerableRel.Prefer prefer) {
-            
+        public EnumerableRel.Result visitChild(EnumerableRel parent, int ordinal, EnumerableRel child,
+                EnumerableRel.Prefer prefer) {
+
             if (calciteDebug) {
                 OLAPContext context;
                 if (child instanceof OLAPRel)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services