mkaravel commented on code in PR #52316:
URL: https://github.com/apache/spark/pull/52316#discussion_r2347025153


##########
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:
   The `sortKeyFunction` is set when you construct the collation. If you look 
at the code in that file you will realize the the logic of how to construct the 
`sortKeyFunction` is really the same logic as for getting the collation key as 
a byte array.
   In fact the `getCollationKeyBytes` method can be rewritten in a mush simpler 
way by using the `sortKeyFunction` from the collation.



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

Reply via email to