cloud-fan commented on a change in pull request #28490:
URL: https://github.com/apache/spark/pull/28490#discussion_r481119430
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -1325,25 +1325,54 @@ 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, we will trim Struct field alias. When
isTopLevel = true,
+ * we won't trim top-level Struct field alias.
+ * @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 = {
+
+ // Explain for param trimAlias and isTopLevel:
+ // 1. trimAlias = false:
+ // We won't trim Struct Field alias.
+ // 2. trimAlias = true && isTopLevel = false:
+ // We will trim all Struct field alias.
+ // 3. trimAlias = true && isTopLevel = 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 needed.
+ def innerResolve(
+ e: Expression,
+ isTopLevel: Boolean): Expression = {
Review comment:
nit: we can put the above 3 lines into one line
----------------------------------------------------------------
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]