-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-13763] [SQL] Remove Project when its Child's Output is Nil #11599
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 |
|---|---|---|
|
|
@@ -157,6 +157,14 @@ class ColumnPruningSuite extends PlanTest { | |
| comparePlans(Optimize.execute(query), expected) | ||
| } | ||
|
|
||
| test("Eliminate the Project with an empty projectList") { | ||
| val input = OneRowRelation | ||
| val query = | ||
| Project(Literal(1).as("1") :: Nil, Project(Literal(1).as("1") :: Nil, input)).analyze | ||
|
||
| val expected = Project(Literal(1).as("1") :: Nil, input).analyze | ||
| comparePlans(Optimize.execute(query), expected) | ||
| } | ||
|
|
||
| test("column pruning for group") { | ||
| val testRelation = LocalRelation('a.int, 'b.int, 'c.int) | ||
| val originalQuery = | ||
|
|
||
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.
I'm thinking of the correctness of this rule. Actually this is not column pruning, but add more columns, as
childmay have more one columns.And why this rule
case p @ Project(projectList, child) if sameOutput(child.output, p.output) => childcan't work?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.
Because
OneRowRelationhas no output. So its output is different to its parentProject.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.
But a
Projectwith empty projectList also has no output right?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.
case p @ Project(_, l: LeafNode) => pThere is another case above it. Thus, it will stop here.
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 this?
Then, we do not need the first line.
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.
Yea. As I posted before. I added a new rule that has side-effect to fix this issue too.
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.
Thanks @viirya @cloud-fan !
I am not sure which way is better.
My concern is the above line looks more hacky than the current PR fix.
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.
Let me respond the original question by @cloud-fan
We will not see an empty
Project, if the child has more than one columns. The emptyProjectonly happens afterPruningColumns. I am fine, if we want to add an extra rule for eliminatingProjectonly.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 we just move that case ahead? It seems always safe to apply
case p @ Project(projectList, child) if sameOutput(child.output, p.output) => childThere 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 thought we intentionally did it in this way. I am not 100% sure if we might hit any issue because of it. Let me try it and check if we will hit any test case failure.