zhengruifeng commented on code in PR #39925:
URL: https://github.com/apache/spark/pull/39925#discussion_r1104003572
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -369,4 +381,47 @@ trait ColumnResolutionHelper extends Logging {
throws = true,
allowOuter = allowOuter)
}
+
+ private def resolveExpressionByPlanId(
+ e: Expression,
+ q: LogicalPlan): Expression = {
+ if (!e.exists(_.getTagValue(LogicalPlan.PLAN_ID_TAG).nonEmpty)) {
+ return e
+ }
+
+ e match {
+ case u: UnresolvedAttribute =>
+ resolveUnresolvedAttributeByPlanId(u, q).getOrElse(u)
+ case l: LeafExpression => l
+ case _ =>
+ e.mapChildren(c => resolveExpressionByPlanId(c, q))
+ }
+ }
+
+ private def resolveUnresolvedAttributeByPlanId(
+ u: UnresolvedAttribute,
+ q: LogicalPlan): Option[AttributeReference] = {
+ 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) {
+ throw new AnalysisException(s"When resolving $u, " +
+ s"fail to find subplan with plan_id=$planId in $q")
+ }
+ val plan = planOpt.get
+
+ try {
+ plan.resolve(u.nameParts, conf.resolver) match {
+ case Some(attr: AttributeReference) => Some(attr)
Review Comment:
got it, will update
--
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]