ilicmarkodb commented on code in PR #54284:
URL: https://github.com/apache/spark/pull/54284#discussion_r2804499450


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CollationTypeCoercion.scala:
##########
@@ -479,6 +484,30 @@ object CollationTypeCoercion extends SQLConfHelper {
          _: StringSplitSQL | _: In | _: InSubquery | _: FindInSet => false
     case _ => true
   }
+
+  /**
+   * Pre-tags [[CommonExpressionRef]]s in [[With]] expressions with the 
collation context of their
+   * definitions. This must be called before the bottom-up expression 
transformation, because that
+   * transformation processes inner expressions (like [[EqualTo]]) before 
reaching the [[With]]
+   * node. Without the enclosing [[With]], we have no context for what the 
refs point to, so we
+   * cannot correctly determine their collation strength.
+   */
+  private[analysis] def preTagCommonExpressionRefs(plan: LogicalPlan): 
LogicalPlan = {
+    plan.resolveExpressionsDown {
+      case withExpression: With =>
+        withExpression.child.foreach {
+          case ref: CommonExpressionRef =>
+            withExpression.defs.find(d => d.id == ref.id && d.child.resolved)
+              .foreach { definition =>
+                findCollationContext(definition.child).foreach { context =>
+                  ref.setTagValue(COLLATION_CONTEXT_TAG, context)
+                }
+              }
+          case _ =>
+        }
+        withExpression
+    }
+  }

Review Comment:
   It’s not directly related to the rule cycle issue, but it’s still needed for 
the correct behaviour of the test



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