Skip to content

[SPARK-42049][SQL][FOLLOWUP] Always filter away invalid ordering/partitioning - #40137

Closed
cloud-fan wants to merge 2 commits into
apache:masterfrom
cloud-fan:alias
Closed

[SPARK-42049][SQL][FOLLOWUP] Always filter away invalid ordering/partitioning#40137
cloud-fan wants to merge 2 commits into
apache:masterfrom
cloud-fan:alias

Conversation

@cloud-fan

@cloud-fancloud-fan commented Feb 23, 2023

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This is a follow-up of #37525 . When the project list has aliases, we go to the projectExpression branch which filters away invalid partitioning/ordering that reference non-existing attributes in the current plan node. However, this filtering is missing when the project list has no alias, where we directly return the child partitioning/ordering.

This PR fixes it.

Why are the changes needed?

to make sure we always return valid output partitioning/ordering.

Does this PR introduce any user-facing change?

no

How was this patch tested?

new tests

@cloud-fan

Copy link
Copy Markdown
ContributorAuthor

cc @peter-toth

@dongjoon-hyundongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@peter-tothpeter-tothFeb 23, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch! Thanks for this follow-up!

But, I'm not sure this part is correct as sortOrder.children should be filtered with _.references.subsetOf(outputSet) separately.

E.g. this test (is a bit artifical though) fails now:

 test("SPARK-42049: Improve AliasAwareOutputExpression - no alias but still prune expressions 2") {
withSQLConf(SQLConf.OPTIMIZER_EXCLUDED_RULES.key ->
Seq(CollapseProject.ruleName, ColumnPruning.ruleName).mkString(",")) {
val df = spark.range(2).select($"id" as "a", $"id" as "b").select($"a")
val outputOrdering = df.queryExecution.optimizedPlan.outputOrdering
assert(outputOrdering.size == 1)
assert(outputOrdering.head.child.asInstanceOf[Attribute].name == "a")
assert(outputOrdering.head.sameOrderExpressions.size == 0)
}
}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

good point!

@viirya

Copy link
Copy Markdown
Member

Hmm, the failed test seems a related one.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Oh is it still failing?

@viirya

Copy link
Copy Markdown
Member

I think it was failing due to latest commit.

@cloud-fan

Copy link
Copy Markdown
ContributorAuthor

The failed test checks invalid ordering and I've updated it.

dongjoon-hyun pushed a commit that referenced this pull request Feb 24, 2023
…itioning
### What changes were proposed in this pull request?
This is a follow-up of #37525 . When the project list has aliases, we go to the `projectExpression` branch which filters away invalid partitioning/ordering that reference non-existing attributes in the current plan node. However, this filtering is missing when the project list has no alias, where we directly return the child partitioning/ordering.
This PR fixes it.
### Why are the changes needed?
to make sure we always return valid output partitioning/ordering.
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
new tests
Closes#40137 from cloud-fan/alias.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 72922ad)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@dongjoon-hyun

Copy link
Copy Markdown
Member

Merged to master/3.4.
Thank you, @cloud-fan , @peter-toth , @viirya .

snmvaughan pushed a commit to snmvaughan/spark that referenced this pull request Jun 20, 2023
…itioning
### What changes were proposed in this pull request?
This is a follow-up of apache#37525 . When the project list has aliases, we go to the `projectExpression` branch which filters away invalid partitioning/ordering that reference non-existing attributes in the current plan node. However, this filtering is missing when the project list has no alias, where we directly return the child partitioning/ordering.
This PR fixes it.
### Why are the changes needed?
to make sure we always return valid output partitioning/ordering.
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
new tests
Closesapache#40137 from cloud-fan/alias.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 72922ad)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@cloud-fan@viirya@dongjoon-hyun@peter-toth