Skip to content
Permalink
Browse files
DRILL-6487: Limit estimateRowCount should not return negative rowcount
closes #1322
  • Loading branch information
Gautam Parai authored and ilooner committed Jun 16, 2018
1 parent ac8e698 commit ca39cb67987a0efff2fe889ca4c5bf3a6fe5273a
Showing 2 changed files with 9 additions and 1 deletion.
@@ -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;
@@ -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\\]\\).*"});
}
}

0 comments on commit ca39cb6

Please sign in to comment.