dbatomic commented on code in PR #46722:
URL: https://github.com/apache/spark/pull/46722#discussion_r1622190538
##########
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 = {
Review Comment:
Hey, can you add a comment explaining what is happening here.
I think that it is not obvious why we are inserting `CollationKey` as a
rule. I would appreciate comment header on top of `RewriteCollationJoin` that
explains why and what we are doing here.
--
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]