uros-db commented on code in PR #46722:
URL: https://github.com/apache/spark/pull/46722#discussion_r1622570360


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/RewriteCollationJoin.scala:
##########
@@ -17,29 +17,68 @@
 
 package org.apache.spark.sql.catalyst.analysis
 
-import org.apache.spark.sql.catalyst.expressions.{AttributeReference, 
CollationKey, Equality}
+import org.apache.spark.sql.catalyst.expressions._
 import org.apache.spark.sql.catalyst.plans.logical.{Join, LogicalPlan}
 import org.apache.spark.sql.catalyst.rules.Rule
 import org.apache.spark.sql.catalyst.util.CollationFactory
+import org.apache.spark.sql.types._
 import org.apache.spark.sql.types.StringType
+import org.apache.spark.util.ArrayImplicits.SparkArrayOps
 
 object RewriteCollationJoin extends Rule[LogicalPlan] {
   def apply(plan: LogicalPlan): LogicalPlan = plan transform {
     case j @ Join(_, _, _, Some(condition), _) =>
       val newCondition = condition transform {
         case e @ Equality(l: AttributeReference, r: AttributeReference) =>
-          (l.dataType, r.dataType) match {
-            case (st: StringType, _: StringType)
-              if 
!CollationFactory.fetchCollation(st.collationId).supportsBinaryEquality =>
-                e.withNewChildren(Seq(CollationKey(l), CollationKey(r)))
-            case _ =>
-              e
-          }
+          e.withNewChildren(Seq(processExpression(l, l.dataType), 
processExpression(r, r.dataType)))
       }
       if (!newCondition.fastEquals(condition)) {
         j.copy(condition = Some(newCondition))
       } else {
         j
       }
   }
+
+  private def processExpression(expr: Expression, dt: DataType): Expression = {
+    dt match {
+      case st: StringType
+        if 
!CollationFactory.fetchCollation(st.collationId).supportsBinaryEquality =>
+          CollationKey(expr)
+
+      case StructType(fields) =>
+        processStruct(expr, fields)
+
+      case ArrayType(et, containsNull) =>
+        processArray(expr, et, containsNull)
+
+      case _ =>
+        expr
+    }
+  }
+
+  private def processStruct(str: Expression, fields: Array[StructField]): 
Expression = {
+    val struct = CreateNamedStruct(fields.zipWithIndex.flatMap {
+      case (f, i) =>
+        Seq(Literal(f.name),
+          processExpression(GetStructField(str, i, Some(f.name)), f.dataType))
+    }.toImmutableArraySeq)
+    if (struct.valExprs.forall(_.isInstanceOf[GetStructField])) {

Review Comment:
   Or even better, we can short-circuit right away for all binary stable 
expressions in `processExpression`.
   
   As for the naming, all these methods are private and internal to 
`RewriteCollationJoin` - I've added comments explaining what's going on, so I 
hope this should be enough



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