-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22944][SQL] improve FoldablePropagation #20139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -508,7 +508,7 @@ object NullPropagation extends Rule[LogicalPlan] { | |
| /** | ||
| * Replace attributes with aliases of the original foldable expressions if possible. | ||
| * Other optimizations will take advantage of the propagated foldable expressions. For example, | ||
| * This rule can optimize | ||
| * this rule can optimize | ||
| * {{{ | ||
| * SELECT 1.0 x, 'abc' y, Now() z ORDER BY x, y, 3 | ||
| * }}} | ||
|
|
@@ -535,7 +535,7 @@ object FoldablePropagation extends Rule[LogicalPlan] { | |
| } else { | ||
| CleanupAliases(plan.transformUp { | ||
| // We can only propagate foldables for a subset of unary nodes. | ||
| case u: UnaryNode if canPropagateFoldables(u) => | ||
| case u: UnaryNode if foldableMap.nonEmpty && canPropagateFoldables(u) => | ||
| u.transformExpressions(replaceFoldable) | ||
|
|
||
| // Join derives the output attributes from its child while they are actually not the | ||
|
|
@@ -544,7 +544,7 @@ object FoldablePropagation extends Rule[LogicalPlan] { | |
| // propagating the foldable expressions. | ||
| // TODO(cloud-fan): It seems more reasonable to use new attributes as the output attributes | ||
| // of outer join. | ||
| case j @ Join(left, right, joinType, _) => | ||
| case j @ Join(left, right, joinType, _) if foldableMap.nonEmpty => | ||
| val newJoin = j.transformExpressions(replaceFoldable) | ||
| val missDerivedAttrsSet: AttributeSet = AttributeSet(joinType match { | ||
| case _: InnerLike | LeftExistence(_) => Nil | ||
|
|
@@ -557,22 +557,16 @@ object FoldablePropagation extends Rule[LogicalPlan] { | |
| }.toSeq) | ||
| newJoin | ||
|
|
||
| // Similar to Join, Expand also miss-derives output attributes from child attributes, we | ||
| // should exclude them when propagating. | ||
| // TODO(hvanhovell): Expand should use new attributes as the output attributes. | ||
| case expand: Expand => | ||
| val newExpand = expand.copy(projections = expand.projections.map { projection => | ||
| // We can not replace the attributes in `Expand.output`. If there are other non-leaf | ||
| // operators that have the `output` field, we should put them here too. | ||
| case expand: Expand if foldableMap.nonEmpty => | ||
| expand.copy(projections = expand.projections.map { projection => | ||
| projection.map(_.transform(replaceFoldable)) | ||
| }) | ||
| val missDerivedAttrsSet = expand.child.outputSet | ||
| foldableMap = AttributeMap(foldableMap.baseMap.values.filterNot { | ||
| case (attr, _) => missDerivedAttrsSet.contains(attr) | ||
| }.toSeq) | ||
|
||
| newExpand | ||
|
|
||
| // For other plans, they are not safe to apply foldable propagation, and they should not | ||
| // propagate foldable expressions from children. | ||
| case other => | ||
| case other if foldableMap.nonEmpty => | ||
| val childrenOutputSet = AttributeSet(other.children.flatMap(_.output)) | ||
| foldableMap = AttributeMap(foldableMap.baseMap.values.filterNot { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we directly set
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can't as it may not be empty. We may have new attributes produced by operators above those unsupported operators. |
||
| case (attr, _) => childrenOutputSet.contains(attr) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about renaming
missDerivedAttrsSettonullSupplyingAttrsSetThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep the word
missas it's really a mistake. We should fix it eventually.