[
https://issues.apache.org/jira/browse/DRILL-6487?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16514691#comment-16514691
]
ASF GitHub Bot commented on DRILL-6487:
---------------------------------------
ilooner closed pull request #1322: DRILL-6487: Limit estimateRowCount should
not return negative rowcount
URL: https://github.com/apache/drill/pull/1322
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/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 afe5dadf22..7d070b6aca 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 double estimateRowCount(RelMetadataQuery mq) {
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 3f5fee21ba..087191aae8 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 void dontPushdownIntoTopNWhenNoLimit() throws
Exception {
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\\]\\).*"});
+ }
}
----------------------------------------------------------------
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:
[email protected]
> Negative row count when selecting from a json file with an OFFSET clause
> ------------------------------------------------------------------------
>
> Key: DRILL-6487
> URL: https://issues.apache.org/jira/browse/DRILL-6487
> Project: Apache Drill
> Issue Type: Bug
> Components: Query Planning & Optimization
> Affects Versions: 1.13.0
> Reporter: Boaz Ben-Zvi
> Assignee: Gautam Kumar Parai
> Priority: Major
> Labels: ready-to-commit
> Fix For: 1.14.0
>
>
> This simple query fails:
> {code}
> select * from dfs.`/data/foo.json` offset 1 row;
> {code}
> where foo.json is
> {code}
> {"key": "aa", "sales": 11}
> {"key": "bb", "sales": 22}
> {code}
> The error returned is:
> {code}
> 0: jdbc:drill:zk=local> select * from dfs.`/data/foo.json` offset 1 row;
> Error: SYSTEM ERROR: AssertionError
> [Error Id: 960d66a9-b480-4a7e-9a25-beb4928e8139 on 10.254.130.25:31020]
> (org.apache.drill.exec.work.foreman.ForemanException) Unexpected exception
> during fragment initialization: null
> org.apache.drill.exec.work.foreman.Foreman.run():282
> java.util.concurrent.ThreadPoolExecutor.runWorker():1142
> java.util.concurrent.ThreadPoolExecutor$Worker.run():617
> java.lang.Thread.run():745
> Caused By (java.lang.AssertionError) null
> org.apache.calcite.rel.metadata.RelMetadataQuery.isNonNegative():900
> org.apache.calcite.rel.metadata.RelMetadataQuery.validateResult():919
> org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount():236
> org.apache.calcite.rel.SingleRel.estimateRowCount():68
>
> org.apache.drill.exec.planner.physical.visitor.ExcessiveExchangeIdentifier$MajorFragmentStat.add():103
>
> org.apache.drill.exec.planner.physical.visitor.ExcessiveExchangeIdentifier.visitPrel():76
>
> org.apache.drill.exec.planner.physical.visitor.ExcessiveExchangeIdentifier.visitPrel():32
>
> org.apache.drill.exec.planner.physical.visitor.BasePrelVisitor.visitProject():50
> org.apache.drill.exec.planner.physical.ProjectPrel.accept():98
>
> org.apache.drill.exec.planner.physical.visitor.ExcessiveExchangeIdentifier.visitScreen():63
>
> org.apache.drill.exec.planner.physical.visitor.ExcessiveExchangeIdentifier.visitScreen():32
> org.apache.drill.exec.planner.physical.ScreenPrel.accept():65
>
> org.apache.drill.exec.planner.physical.visitor.ExcessiveExchangeIdentifier.removeExcessiveEchanges():41
>
> org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler.convertToPrel():557
> org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler.getPlan():179
> org.apache.drill.exec.planner.sql.DrillSqlWorker.getQueryPlan():145
> org.apache.drill.exec.planner.sql.DrillSqlWorker.getPlan():83
> org.apache.drill.exec.work.foreman.Foreman.runSQL():567
> org.apache.drill.exec.work.foreman.Foreman.run():264
> java.util.concurrent.ThreadPoolExecutor.runWorker():1142
> java.util.concurrent.ThreadPoolExecutor$Worker.run():617
> java.lang.Thread.run():745 (state=,code=0)
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)