Repository: drill
Updated Branches:
  refs/heads/master a0c178bab -> d622f76ee


DRILL-5165: For limit all case, no need to push down limit to scan


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/d622f76e
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/d622f76e
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/d622f76e

Branch: refs/heads/master
Commit: d622f76ee6336d97c9189fc589befa7b0f4189d6
Parents: a0c178b
Author: chunhui-shi <c...@maprtech.com>
Authored: Tue Mar 7 23:39:32 2017 -0800
Committer: Arina Ielchiieva <arina.yelchiy...@gmail.com>
Committed: Fri Jul 21 20:36:29 2017 +0300

----------------------------------------------------------------------
 .../planner/logical/DrillPushLimitToScanRule.java   | 16 ++++++++++++++--
 .../physical/impl/limit/TestLimitWithExchanges.java |  9 +++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/d622f76e/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
index 9f762f0..8ce26c8 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
@@ -42,8 +42,14 @@ public abstract class DrillPushLimitToScanRule extends 
RelOptRule {
       RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
     @Override
     public boolean matches(RelOptRuleCall call) {
+      DrillLimitRel limitRel = call.rel(0);
       DrillScanRel scanRel = call.rel(1);
-      return scanRel.getGroupScan().supportsLimitPushdown(); // For now only 
applies to Parquet.
+      // For now only applies to Parquet. And pushdown only apply limit but 
not offset,
+      // so if getFetch() return null no need to run this rule.
+      if (scanRel.getGroupScan().supportsLimitPushdown() && 
(limitRel.getFetch() != null)) {
+        return true;
+      }
+      return false;
     }
 
     @Override
@@ -58,8 +64,14 @@ public abstract class DrillPushLimitToScanRule extends 
RelOptRule {
       RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.some(DrillProjectRel.class, 
RelOptHelper.any(DrillScanRel.class))), 
"DrillPushLimitToScanRule_LimitOnProject") {
     @Override
     public boolean matches(RelOptRuleCall call) {
+      DrillLimitRel limitRel = call.rel(0);
       DrillScanRel scanRel = call.rel(2);
-      return scanRel.getGroupScan().supportsLimitPushdown(); // For now only 
applies to Parquet.
+      // For now only applies to Parquet. And pushdown only apply limit but 
not offset,
+      // so if getFetch() return null no need to run this rule.
+      if (scanRel.getGroupScan().supportsLimitPushdown() && 
(limitRel.getFetch() != null)) {
+        return true;
+      }
+      return false;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/d622f76e/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestLimitWithExchanges.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestLimitWithExchanges.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestLimitWithExchanges.java
index 18f181b..ae7c57b 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestLimitWithExchanges.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestLimitWithExchanges.java
@@ -125,6 +125,15 @@ public class TestLimitWithExchanges extends BaseTestQuery {
     }
   }
 
+  @Test
+  public void TestLimitAllOnParquet() throws Exception {
+    final String query = String.format("select t.n_nationkey from 
cp.`tpch/nation.parquet` t limit all offset 5", TEST_RES_PATH);
+    final String [] expectedPlan = {};
+    final String [] excludedPlan = {"UnionExchange"};
+
+    testLimitHelper(query, expectedPlan, excludedPlan, 20);
+  }
+
   private void testLimitHelper(final String sql, final String[] expectedPlan, 
final String[] excludedPattern, int expectedRecordCount) throws Exception {
     // Validate the plan
     PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPattern);

Reply via email to