Github user chenghao-intel commented on a diff in the pull request:
https://github.com/apache/spark/pull/9055#discussion_r42586165
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
@@ -408,6 +552,25 @@ class Analyzer(
}
}
+ // Try to resolve the attributes from the given logical plan
+ def tryResolveAttributes(expr: Expression, q: LogicalPlan): Expression
= {
+ checkAnalysis(q)
+ val projection = Project(q.output, q)
+
+ logTrace(s"Attempting to resolve ${expr.simpleString}")
+ expr transformUp {
+ case u @ UnresolvedAlias(expr) => expr
+ case u @ UnresolvedAttribute(nameParts) =>
+ // Leave unchanged if resolution fails. Hopefully will be
resolved next round.
+ val result =
+ withPosition(u) { projection.resolveChildren(nameParts,
resolver).getOrElse(u) }
+ logDebug(s"Resolving $u to $result")
+ result
+ case UnresolvedExtractValue(child, fieldExpr) if child.resolved =>
+ ExtractValue(child, fieldExpr, resolver)
+ }
+ }
+
--- End diff --
This is the rule that I copied from the `ResolveReferences` with slight
changes, maybe we should leave it along `ResolveReferences`, otherwise people
probably forgot to update it once we need to update the logic of attributes
resolution.
And I was planning to move this code into the `LogicalPlan`, but need more
thinking how to make the code shared with the rule `ResolveReferences`, how
about leave it for the further improvement?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]