anchovYu commented on code in PR #38851:
URL: https://github.com/apache/spark/pull/38851#discussion_r1037696777
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -2109,6 +2110,51 @@ class Analyzer(override val catalogManager:
CatalogManager)
}
}
+ /**
+ * Resolves `UnresolvedAttribute` to `OuterReference` if we are resolving
subquery plans (when
+ * `AnalysisContext.get.outerPlan` is set).
+ */
+ object ResolveOuterReferences extends Rule[LogicalPlan] {
+ override def apply(plan: LogicalPlan): LogicalPlan = {
+ // Only apply this rule if we are resolving subquery plans.
+ if (AnalysisContext.get.outerPlan.isEmpty) return plan
+
+ // We must run these 3 rules first, as they also resolve
`UnresolvedAttribute` and have
+ // higher priority than outer reference resolution.
+ val prepared =
ResolveAggregateFunctions(ResolveMissingReferences(ResolveReferences(plan)))
Review Comment:
Also it's a bit strange when there is no outer reference to resolve but the
3 rules take effect, the plan change logger of this ResolveOuterReferences
actually shows the changes from these 3 rules.
```
=== Applying Rule
org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveOuterReferences ===
'Project [id2#28L]
'Project [id2#28L]
+- 'SubqueryAlias __auto_generated_subquery_name
+- 'SubqueryAlias __auto_generated_subquery_name
! +- 'Project [id#27, ('id + cast(1 as bigint)) AS id2#28]
+- 'Project [id#27, (id#27 + cast(1 as
bigint)) AS id2#28]
..
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]