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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -4082,3 +4084,31 @@ object RemoveTempResolvedColumn extends 
Rule[LogicalPlan] {
     }
   }
 }
+
+object ReassignAliasNamesWithCollations extends Rule[LogicalPlan] {
+  override def apply(plan: LogicalPlan): LogicalPlan = {
+    plan.resolveExpressionsWithPruning(_.containsPattern(ALIAS)) {
+      case a: Alias if
+          a.resolved &&
+          a.metadata.contains(AUTO_GENERATED_ALIAS) &&
+          hasNonDefaultCollationInTheSubtree(a.child) =>
+        val newName = toPrettySQL(a.child)
+        if (newName != a.name) {
+          a.withName(newName)
+        } else {
+          a
+        }
+    }
+  }
+
+  private def hasNonDefaultCollationInTheSubtree(rootExpression: Expression) = 
{
+    rootExpression.exists {
+      case expression =>
+        val dataType = try { Some(expression.dataType) } catch { case ex: 
Throwable => None }

Review Comment:
   `.dataType` should only be called on resolved expressions. Can you provide 
the error stacktrace? I don't think we will see errors for resolved expressions.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to