Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/10451#discussion_r48582039
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
---
@@ -80,6 +81,33 @@ abstract class Optimizer extends
RuleExecutor[LogicalPlan] {
object DefaultOptimizer extends Optimizer
/**
+ * Pushes down Limit for reducing the amount of returned data.
+ *
+ * 1. Adding Extra Limit beneath the operations, including Union All.
+ * 2. Project is pushed through Limit in the rule ColumnPruning
+ *
+ * Any operator that a Limit can be pushed passed should override the
maxRows function.
+ */
+object PushDownLimit extends Rule[LogicalPlan] {
+
+ def apply(plan: LogicalPlan): LogicalPlan = plan transform {
+
+ // Adding extra Limit below UNION ALL iff both left and right childs
are not Limit or
+ // do not have Limit descendants. This heuristic is valid assuming
there does not exist
+ // any Limit push-down rule that is unable to infer the value of
maxRows.
+ // Note, right now, Union means UNION ALL, which does not de-duplicate
rows. So, it is
+ // safe to pushdown Limit through it. Once we add UNION DISTINCT, we
will not be able to
+ // pushdown Limit.
+ case Limit(exp, Union(left, right))
+ if left.maxRows.isEmpty || right.maxRows.isEmpty =>
--- End diff --
Yeah, that also makes sense. Will do the change after these three running
test cases. : )
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]