ulysses-you commented on a change in pull request #33651:
URL: https://github.com/apache/spark/pull/33651#discussion_r683548974
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -1639,24 +1639,30 @@ object PushPredicateThroughJoin extends
Rule[LogicalPlan] with PredicateHelper {
* 2. Combines two adjacent [[Limit]] operators into one, merging the
* expressions into one single expression.
*/
-object EliminateLimits extends Rule[LogicalPlan] {
+trait EliminateLimitsBase extends Rule[LogicalPlan] {
private def canEliminate(limitExpr: Expression, child: LogicalPlan): Boolean
= {
limitExpr.foldable && child.maxRows.exists { _ <=
limitExpr.eval().asInstanceOf[Int] }
}
- def apply(plan: LogicalPlan): LogicalPlan = plan.transformDownWithPruning(
- _.containsPattern(LIMIT), ruleId) {
+ def commonApplyFunc: PartialFunction[LogicalPlan, LogicalPlan] = {
case Limit(l, child) if canEliminate(l, child) =>
child
case GlobalLimit(l, child) if canEliminate(l, child) =>
child
case GlobalLimit(le, GlobalLimit(ne, grandChild)) =>
- GlobalLimit(Least(Seq(ne, le)), grandChild)
+ GlobalLimit(Literal(Least(Seq(ne, le)).eval().asInstanceOf[Int]),
grandChild)
Review comment:
It's flaky that this expression highly depend on `ConstantFolding`.
--
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]