-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-13351] [SQL] fix column pruning on Expand #11225
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 all commits
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 |
|---|---|---|
|
|
@@ -300,6 +300,16 @@ object SetOperationPushDown extends Rule[LogicalPlan] with PredicateHelper { | |
| */ | ||
| object ColumnPruning extends Rule[LogicalPlan] { | ||
| def apply(plan: LogicalPlan): LogicalPlan = plan transform { | ||
| case a @ Aggregate(_, _, e @ Expand(projects, output, child)) | ||
| if (e.outputSet -- a.references).nonEmpty => | ||
| val newOutput = output.filter(a.references.contains(_)) | ||
| val newProjects = projects.map { proj => | ||
| proj.zip(output).filter { case (e, a) => | ||
|
Contributor
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. The projection has as many expressions as there are output fields, which is why this The goal of this block is to keep only the expressions whose output columns are referenced by the aggregate. |
||
| newOutput.contains(a) | ||
| }.unzip._1 | ||
|
Contributor
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. I think this is equivalent to |
||
| } | ||
| a.copy(child = Expand(newProjects, newOutput, child)) | ||
|
|
||
| case a @ Aggregate(_, _, e @ Expand(_, _, child)) | ||
|
Contributor
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. This rule is slightly different: this prunes columns on |
||
| if (child.outputSet -- e.references -- a.references).nonEmpty => | ||
| a.copy(child = e.copy(child = prunedChild(child, e.references ++ a.references))) | ||
|
|
||
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.
To summarize my understanding for other reviewers:
This new rule handles the case where you have an expand beneath an aggregate and the expand produces rows with columns which are not referenced by the aggregate operator. In this case, we want to rewrite the expand's projections in order to eliminate the unreferenced column.