Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
* }}}
Expand All @@ -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
Expand All @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table expressions on either side of a left or right outer join are referred to as preserved and null-supplying. In a left outer join, the left-hand table expression is preserved and the right-hand table expression is null-supplying.

How about renaming missDerivedAttrsSet to nullSupplyingAttrsSet

Copy link
Contributor Author

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 miss as it's really a mistake. We should fix it eventually.

case _: InnerLike | LeftExistence(_) => Nil
Expand All @@ -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)
Copy link
Member

@dongjoon-hyun dongjoon-hyun Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this back.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we directly set foldableMap to an empty map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down