cloud-fan commented on code in PR #36417:
URL: https://github.com/apache/spark/pull/36417#discussion_r866824230
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -1871,21 +1874,18 @@ object EliminateLimits extends Rule[LogicalPlan] {
}
/**
- * Rewrite [[Offset]] as [[GlobalLimitAndOffset]] or [[LocalLimit]],
- * merging the expressions into one single expression. See [[Limit]] for more
information
- * about the difference between [[LocalLimit]] and [[GlobalLimit]].
+ * This rule optimizes Offset operators by:
+ * 1. Eliminate [[Offset]] operators if offset == 0.
+ * 2. Replace [[Offset]] operators to empty [[LocalRelation]]
+ * if [[Offset]]'s child max row <= offset.
*/
-object RewriteOffsets extends Rule[LogicalPlan] {
+object EliminateOffsets extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
- case GlobalLimit(le, Offset(oe, grandChild)) =>
- GlobalLimitAndOffset(le, oe, grandChild)
- case localLimit @ LocalLimit(le, Offset(oe, grandChild)) =>
- val offset = oe.eval().asInstanceOf[Int]
- if (offset == 0) {
- localLimit.withNewChildren(Seq(grandChild))
- } else {
- Offset(oe, LocalLimit(Add(le, oe), grandChild))
- }
+ case Offset(oe, child) if oe.foldable && oe.eval().asInstanceOf[Int] == 0
=>
+ child
+ case Offset(oe, child)
+ if oe.foldable && child.maxRows.exists(_ <= oe.eval().asInstanceOf[Int])
=>
+ LocalRelation(child.output, data = Seq.empty, isStreaming =
plan.isStreaming)
Review Comment:
```suggestion
LocalRelation(child.output, data = Seq.empty, isStreaming =
child.isStreaming)
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]