vladimirg-db commented on code in PR #50192:
URL: https://github.com/apache/spark/pull/50192#discussion_r1995424455
##########
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:
If we were to filter out just the `WindowSpecDefinition` and `WindowFrame`,
we would miss some other stuff like `AlterColumnSpec`, which throws other
exceptions...

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