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


##########
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:
   Looking into it more, the rule `CollationTypeCoercion` adds collation by 
changing the string type in `Literal` and `Cast`, or add a new `Cast`.
   
   We don't need to check data type on all expressions here, just find 
`Literal` and `Cast` and check the type.



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