uros-db commented on code in PR #46917:
URL: https://github.com/apache/spark/pull/46917#discussion_r1635228255
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/interfaces.scala:
##########
@@ -702,3 +706,55 @@ abstract class TypedAggregateWithHashMapAsBuffer
}
}
}
+
+object CollationAwareFunctionRegistry {
+ def bytesToHashFunction(dataType: DataType): AnyRef => Long = {
+ val hashFunction = dataType match {
+ case s: StringType => a: AnyRef =>
CollationFactory.fetchCollation(s.collationId)
+ .hashFunction.applyAsLong(a.asInstanceOf[UTF8String])
+ case nb: StructType if !UnsafeRowUtils.isBinaryStable(nb) => a: AnyRef =>
+
a.asInstanceOf[InternalRow].toSeq(nb).zip(nb.fields.toSeq).foldLeft(0L)((acc, b)
+ => acc ^ bytesToHashFunction(b._2.dataType)(b._1.asInstanceOf[AnyRef]))
+ case _ => a: AnyRef => a.hashCode().toLong
+ }
+ hashFunction
+ }
+ def bytesToEqualFunction(dataType: DataType): (AnyRef, AnyRef) => Boolean = {
+ val equalFunction = dataType match {
+ case s: StringType => (a: AnyRef, b: AnyRef) =>
+ a.asInstanceOf[UTF8String].semanticEquals(b.asInstanceOf[UTF8String],
s.collationId)
+ case nb: StructType if !UnsafeRowUtils.isBinaryStable(nb) => (a: AnyRef,
b: AnyRef) =>
+ a.asInstanceOf[InternalRow].toSeq(nb)
+ .zip(b.asInstanceOf[InternalRow].toSeq(nb)).zipWithIndex
+ .forall { case ((a, b), i) =>
+ bytesToEqualFunction(
+ nb.fields(i).dataType
+ )(a.asInstanceOf[AnyRef], b.asInstanceOf[AnyRef])
+ }
+ case _ => (a: AnyRef, b: AnyRef) =>
+ a.equals(b)
+ }
+ equalFunction
+
+ }
+}
Review Comment:
these look like general collations-related Util methods, perhaps we should
place this elsewhere (for example, into CollationFactory)
--
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]