Skip to content
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

[SPARK-22944][SQL] improve FoldablePropagation #20139

Closed
wants to merge 3 commits into from

Conversation

cloud-fan
Copy link
Contributor

@cloud-fan cloud-fan commented Jan 3, 2018

What changes were proposed in this pull request?

FoldablePropagation is a little tricky as it needs to handle attributes that are miss-derived from children, e.g. outer join outputs. This rule does a kind of stop-able tree transform, to skip to apply this rule when hit a node which may have miss-derived attributes.

Logically we should be able to apply this rule above the unsupported nodes, by just treating the unsupported nodes as leaf nodes. This PR improves this rule to not stop the tree transformation, but reduce the foldable expressions that we want to propagate.

How was this patch tested?

existing tests

@cloud-fan
Copy link
Contributor Author

@SparkQA
Copy link

SparkQA commented Jan 3, 2018

Test build #85624 has finished for PR 20139 at commit b4787f7.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor Author

retest this please

* Other optimizations will take advantage of the propagated foldable expressions.
*
* Other optimizations will take advantage of the propagated foldable expressions. For example,
* This rule can optimize
Copy link
Member

Choose a reason for hiding this comment

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

This -> this

j.transformExpressions(replaceFoldable)
case j @ Join(left, right, joinType, _) =>
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.

// We can only propagate foldables for a subset of unary nodes.
case u: UnaryNode if !stop && canPropagateFoldables(u) =>
case u: UnaryNode if canPropagateFoldables(u) =>
Copy link
Member

Choose a reason for hiding this comment

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

For all these cases, how about adding another condition if foldableMap.nonEmpty && xyz?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah good catch!

// and often reuses the underlying attributes; so we cannot assume that a column is still
// foldable after the expand has been applied.
// Similar to Join, Expand also miss-derives output attributes from child attributes, we
// should exclude them when propagating.
Copy link
Member

Choose a reason for hiding this comment

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

After #12496, the above statement is still true?

case other =>
stop = true
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.

@SparkQA
Copy link

SparkQA commented Jan 3, 2018

Test build #85627 has finished for PR 20139 at commit b4787f7.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Oops. I deleted my previous comment. Never mind.

@dongjoon-hyun
Copy link
Member

Thank you for pinging me. LGTM.

@SparkQA
Copy link

SparkQA commented Jan 3, 2018

Test build #85635 has finished for PR 20139 at commit 661e5d9.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

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.


test("Propagate above outer join") {
val left = LocalRelation('a.int).select('a, Literal(1).as('b))
val right = LocalRelation('c.int).select('c, Literal(1).as("d"))
Copy link
Member

Choose a reason for hiding this comment

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

nit. "d" -> 'd

@gatorsmile
Copy link
Member

LGTM

@SparkQA
Copy link

SparkQA commented Jan 4, 2018

Test build #85648 has finished for PR 20139 at commit df75bff.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member

Thanks! Merged to master/2.3

asfgit pushed a commit that referenced this pull request Jan 4, 2018
## What changes were proposed in this pull request?

`FoldablePropagation` is a little tricky as it needs to handle attributes that are miss-derived from children, e.g. outer join outputs. This rule does a kind of stop-able tree transform, to skip to apply this rule when hit a node which may have miss-derived attributes.

Logically we should be able to apply this rule above the unsupported nodes, by just treating the unsupported nodes as leaf nodes. This PR improves this rule to not stop the tree transformation, but reduce the foldable expressions that we want to propagate.

## How was this patch tested?

existing tests

Author: Wenchen Fan <[email protected]>

Closes #20139 from cloud-fan/foldable.

(cherry picked from commit 7d045c5)
Signed-off-by: gatorsmile <[email protected]>
@asfgit asfgit closed this in 7d045c5 Jan 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants