viirya commented on a change in pull request #28490:
URL: https://github.com/apache/spark/pull/28490#discussion_r481281084
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -1325,25 +1325,45 @@ class Analyzer(
*
* Note : In this routine, the unresolved attributes are resolved from the
input plan's
* children attributes.
+ *
+ * @param e The expression need to be resolved.
+ * @param q The LogicalPlan whose children are used to resolve
expression's attribute.
+ * @param trimAlias When true, trim unnecessary alias of `GetStructField`.
Note that,
+ * we cannot trim the alias of top-level
`GetStructField`, as we should
+ * resolve `UnresolvedAttribute` to a named expression.
The caller side
+ * can trim the alias of top-level `GetStructField` if
it's safe to do so.
+ * @return resolved Expression.
*/
- private def resolveExpressionTopDown(e: Expression, q: LogicalPlan):
Expression = {
- if (e.resolved) return e
- e match {
- case f: LambdaFunction if !f.bound => f
- case u @ UnresolvedAttribute(nameParts) =>
- // Leave unchanged if resolution fails. Hopefully will be resolved
next round.
- val result =
- withPosition(u) {
- q.resolveChildren(nameParts, resolver)
- .orElse(resolveLiteralFunction(nameParts, u, q))
- .getOrElse(u)
+ private def resolveExpressionTopDown(
+ e: Expression,
+ q: LogicalPlan,
+ trimAlias: Boolean = false): Expression = {
+
+ def innerResolve(e: Expression, isTopLevel: Boolean): Expression = {
+ if (e.resolved) return e
+ e match {
+ case f: LambdaFunction if !f.bound => f
+ case u @ UnresolvedAttribute(nameParts) =>
+ // Leave unchanged if resolution fails. Hopefully will be resolved
next round.
+ val resolved =
+ withPosition(u) {
+ q.resolveChildren(nameParts, resolver)
+ .orElse(resolveLiteralFunction(nameParts, u, q))
+ .getOrElse(u)
+ }
+ val result = resolved match {
+ case Alias(s: GetStructField, _) if trimAlias && !isTopLevel => s
+ case others => others
}
Review comment:
Actually I'm wondering if there is any cases we don't want to trim
nested (i.e., non top-level) `Alias`? Such `Alias` is useless and could
possibly cause unexpected issue.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]