drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyfar...@apache.org
Subject [drill] 01/03: DRILL-6487: Limit estimateRowCount should not return negative rowcount
Date Sat, 16 Jun 2018 05:45:55 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit ca39cb67987a0efff2fe889ca4c5bf3a6fe5273a
Author: Gautam Parai <gparai@maprtech.com>
AuthorDate: Thu Jun 14 17:26:32 2018 -0700

    DRILL-6487: Limit estimateRowCount should not return negative rowcount
    
    closes #1322
---
 .../org/apache/drill/exec/planner/common/DrillLimitRelBase.java    | 3 ++-
 .../apache/drill/exec/physical/impl/limit/TestLimitPlanning.java   | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillLimitRelBase.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillLimitRelBase.java
index afe5dad..7d070b6 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillLimitRelBase.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillLimitRelBase.java
@@ -87,7 +87,8 @@ public abstract class DrillLimitRelBase extends SingleRel implements DrillRelNod
     int off = offset != null ? RexLiteral.intValue(offset) : 0 ;
 
     if (fetch == null) {
-      return getInput().estimateRowCount(mq) - off;
+      // If estimated rowcount is less than offset return 0
+      return Math.max(0, getInput().estimateRowCount(mq) - off);
     } else {
       int f = RexLiteral.intValue(fetch);
       return off + f;
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestLimitPlanning.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestLimitPlanning.java
index 3f5fee2..087191a 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestLimitPlanning.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestLimitPlanning.java
@@ -29,4 +29,11 @@ public class TestLimitPlanning extends PlanTestBase {
 
     PlanTestBase.testPlanMatchingPatterns(query, new String[]{".*Sort\\(.*"}, new String[]{".*TopN\\(.*"});
   }
+
+  @Test
+  public void offsetMoreThanTotalRowsWithoutFetch() throws Exception {
+    String query = "select full_name from cp.`employee.json` offset 1156";
+    // Should not raise an assert
+    PlanTestBase.testPlanMatchingPatterns(query, new String[]{".*Limit\\(offset=\\[1156\\]\\).*"});
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
timothyfarkas@apache.org.

Mime
View raw message