mkaravel commented on code in PR #52316: URL: https://github.com/apache/spark/pull/52316#discussion_r2347025882
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/datasketchesAggregates.scala: ########## @@ -146,8 +151,11 @@ case class HllSketchAgg( case IntegerType => sketch.update(v.asInstanceOf[Int]) case LongType => sketch.update(v.asInstanceOf[Long]) case st: StringType => - val cKey = CollationFactory.getCollationKey(v.asInstanceOf[UTF8String], st.collationId) - sketch.update(cKey.toString) + val str = v.asInstanceOf[UTF8String] + if (str != null && str.numBytes > 0) { + val cKey = CollationFactory.getCollationKeyBytes(str, st.collationId) + sketch.update(cKey) + } Review Comment: Basically this (this the `getCollationKeyBytes` definition): ```java public static byte[] getCollationKeyBytes(UTF8String input, int collationId) { Collation collation = fetchCollation(collationId); if (collation.supportsSpaceTrimming) { input = Collation.CollationSpec.applyTrimmingPolicy(input, collationId); } if (collation.isUtf8BinaryType) { return input.getBytes(); } else if (collation.isUtf8LcaseType) { return CollationAwareUTF8String.lowerCaseCodePoints(input).getBytes(); } else { return collation.getCollator().getCollationKey( input.toValidString()).toByteArray(); } } ``` is the same as: ```java public static byte[] getCollationKeyBytes(UTF8String input, int collationId) { return fetchCollation(collationId).sortKeyFunction(input); } ``` We need to simplify this code eventually and remove the code duplcation. The `sortKeyFunction` was recently introduced as the result of fixing an issue with how we hash strings... -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org