cloud-fan commented on code in PR #45059:
URL: https://github.com/apache/spark/pull/45059#discussion_r1482291904


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -312,14 +312,39 @@ trait ColumnResolutionHelper extends Logging with 
DataTypeErrorsBase {
       }.map(e => Alias(e, nameParts.last)())
     }
 
-    e.transformWithPruning(_.containsAnyPattern(UNRESOLVED_ATTRIBUTE, 
TEMP_RESOLVED_COLUMN)) {
-      case u: UnresolvedAttribute =>
-        resolve(u.nameParts).getOrElse(u)
-      // Re-resolves `TempResolvedColumn` as variable references if it has 
tried to be resolved with
-      // Aggregate but failed.
-      case t: TempResolvedColumn if t.hasTried =>
-        resolve(t.nameParts).getOrElse(t)
+    def innerResolve(e: Expression, isTopLevel: Boolean): Expression = 
withOrigin(e.origin) {
+      if (e.resolved) return e
+      val resolved = e match {
+        case u @ UnresolvedAttribute(nameParts) =>
+          val result = withPosition(u) {
+            resolve(nameParts).getOrElse(u) match {
+              // We trim unnecessary alias here. Note that, we cannot trim the 
alias at top-level,
+              // as we should resolve `UnresolvedAttribute` to a named 
expression. The caller side
+              // can trim the top-level alias if it's safe to do so. Since we 
will call
+              // CleanupAliases later in Analyzer, trim non top-level 
unnecessary alias is safe.
+              case Alias(child, _) if !isTopLevel => child
+              case other => other
+            }
+          }
+          result
+
+        // Re-resolves `TempResolvedColumn` if it has tried to be resolved 
with Aggregate

Review Comment:
   nit: let's keep the previous comment



-- 
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]

Reply via email to