Skip to content

Commit f462b63

Browse files
cloud-fanyaooqinn
authored andcommitted
[SPARK-43979][SQL][FOLLOWUP] Fix the detection of alias-only project
### What changes were proposed in this pull request? Fix a minor mistake in apache#42408 which is found during the branch 3.5 backport. apache#42449 fixed it `branch-3.5` first. ### Why are the changes needed? To make the code align with 3.5. We may remove `simplifyPlanForCollectedMetrics` entirely as it seems not an issue anymore in the master branch due to how we deduplicate relations. ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? existing tests Closes apache#42453 from cloud-fan/minor. Authored-by: Wenchen Fan <[email protected]> Signed-off-by: Kent Yao <[email protected]>
1 parent 84dbe84 commit f462b63

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,9 +1113,12 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
11131113
private def simplifyPlanForCollectedMetrics(plan: LogicalPlan): LogicalPlan = {
11141114
plan.resolveOperators {
11151115
case p: Project if p.projectList.size == p.child.output.size =>
1116-
val assignExprIdOnly = p.projectList.zip(p.child.output).forall {
1117-
case (left: Alias, right: Attribute) =>
1118-
left.child.semanticEquals(right) && right.name == left.name
1116+
val assignExprIdOnly = p.projectList.zipWithIndex.forall {
1117+
case (Alias(attr: AttributeReference, _), index) =>
1118+
// The input plan of this method is already canonicalized. The attribute id becomes the
1119+
// ordinal of this attribute in the child outputs. So an alias-only Project means the
1120+
// the id of the aliased attribute is the same as its index in the project list.
1121+
attr.exprId.id == index
11191122
case _ => false
11201123
}
11211124
if (assignExprIdOnly) {

0 commit comments

Comments
 (0)