vineetgarg02 commented on a change in pull request #860: HIVE-22408 The fix for
CALCITE-2991 creates wrong results on edge case
URL: https://github.com/apache/hive/pull/860#discussion_r356957099
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSortLimitRemoveRule.java
##########
@@ -41,8 +42,17 @@ public boolean matches(RelOptRuleCall call) {
final HiveSortLimit sortLimit = call.rel(0);
Double maxRowCount =
call.getMetadataQuery().getMaxRowCount(sortLimit.getInput());
- if (maxRowCount != null &&(maxRowCount <= 1)) {
- return true;
+ if (maxRowCount != null) {
+ if (sortLimit.getFetchExpr() != null) {
+ // we have LIMIT
+ int limit = RexLiteral.intValue(sortLimit.getFetchExpr());
+ if (maxRowCount <= limit) {
Review comment:
@kgyrtkirk `MaxRowCount` is guaranteed to return the number of rows which
will be >= the actual number of rows, therefore we should never end up removing
LIMIT when we shoudn't
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]