cloud-fan commented on code in PR #39925:
URL: https://github.com/apache/spark/pull/39925#discussion_r1102233843
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -369,4 +376,59 @@ trait ColumnResolutionHelper extends Logging {
throws = true,
allowOuter = allowOuter)
}
+
+ private def resolveExpressionByPlanId(
+ e: Expression,
+ q: LogicalPlan,
+ allowOuter: Boolean): Expression = {
+ if (!e.exists(_.getTagValue(LogicalPlan.PLAN_ID_TAG).nonEmpty)) {
+ return e
+ }
+
+ e match {
+ case u: UnresolvedAttribute =>
+ resolveUnresolvedAttributeByPlanId(u, q, allowOuter).getOrElse(u)
+ case l: LeafExpression => l
+ case _ =>
+ e.mapChildren(c => resolveExpressionByPlanId(c, q, allowOuter))
+ }
+ }
+
+ private def resolveUnresolvedAttributeByPlanId(
+ u: UnresolvedAttribute,
+ q: LogicalPlan,
+ allowOuter: Boolean): Option[Expression] = {
+ val planIdOpt = u.getTagValue(LogicalPlan.PLAN_ID_TAG)
+ if (planIdOpt.isEmpty) return None
+ val planId = planIdOpt.get
+ logDebug(s"Extract plan_id $planId from $u")
+
+ val planOpt =
q.find(_.getTagValue(LogicalPlan.PLAN_ID_TAG).contains(planId))
+ if (planOpt.isEmpty) return None
+ val plan = planOpt.get
+ logDebug(s"Find child node $plan with plan_id==$planId")
+
+ try {
Review Comment:
I think we can make it simpler:
```
plan.resolve(u.nameParts, conf.resolver)
```
The behavior is expected:
1. no error if can't resolve
2. ok to keep a dangling attribute. This is the same behavior as normal
dataframe, try `df1.select(df2.col)`
3. no outer reference resolution
--
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]