DRILL-5165: For limit all case, no need to push down limit to scan
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 @@
       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 @@
       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
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 @@
     }
   }
 
+  @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);