uros-db commented on code in PR #46526:
URL: https://github.com/apache/spark/pull/46526#discussion_r1598030581
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Mode.scala:
##########
@@ -70,10 +74,22 @@ case class Mode(
buffer
}
- override def eval(buffer: OpenHashMap[AnyRef, Long]): Any = {
- if (buffer.isEmpty) {
+ override def eval(buff: OpenHashMap[AnyRef, Long]): Any = {
+ if (buff.isEmpty) {
return null
}
+ val buffer = if (isCollatedString(child)) {
+ val modeMap = buff.toSeq.groupMapReduce {
+ case (key: String, _) =>
+ CollationFactory.getCollationKey(UTF8String.fromString(key),
collationId)
+ case (key: UTF8String, _) =>
+ CollationFactory.getCollationKey(key, collationId)
+ case (key, _) => key
+ }(x => x)((x, y) => (x._1, x._2 + y._2)).values
+ modeMap
+ } else {
+ buff
+ }
Review Comment:
Going back to the original issue (why Mode doesn't work already, while
otherwise Aggregation generally works with collated strings in Spark), here's
what I'm interested in: why does
`PhysicalDataType.ordering(child.dataType).asInstanceOf[Ordering[AnyRef]]` not
work here automatically?
afaik, ordering for `PhysicalStringType` is defined correctly:
```
private[sql] val ordering =
CollationFactory.fetchCollation(collationId).comparator.compare(_, _)
```
so one would naturally expect Mode to work "as is"
did you investigate this maybe?
--
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]