uros-db commented on code in PR #47154: URL: https://github.com/apache/spark/pull/47154#discussion_r1678100347
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Mode.scala: ########## @@ -86,6 +71,78 @@ case class Mode( buffer } + private def recursivelyGetBufferForArrayType( + a: ArrayType, + data: ArrayData): Seq[Any] = { + (0 until data.numElements()).map { i => + data.get(i, a.elementType) match { + case k: UTF8String if a.elementType.isInstanceOf[StringType] && + !a.elementType.asInstanceOf[StringType].supportsBinaryEquality + => CollationFactory.getCollationKey(k, a.elementType.asInstanceOf[StringType].collationId) + case k if a.elementType.isInstanceOf[StructType] => + recursivelyGetBufferForStructType( + k.asInstanceOf[InternalRow].toSeq(a.elementType.asInstanceOf[StructType]).zip( + a.elementType.asInstanceOf[StructType].fields)) + case k if a.elementType.isInstanceOf[ArrayType] => + recursivelyGetBufferForArrayType( + a.elementType.asInstanceOf[ArrayType], + k.asInstanceOf[ArrayData]) + case k => k + } + } + } + + private def getBufferForComplexType( + buffer: OpenHashMap[AnyRef, Long], + d: DataType): Iterable[(AnyRef, Long)] = { + buffer.groupMapReduce { + case (key: InternalRow, _) if d.isInstanceOf[StructType] => + recursivelyGetBufferForStructType(key.toSeq(d.asInstanceOf[StructType]) + .zip(d.asInstanceOf[StructType].fields)) + case (key: ArrayData, _) if d.isInstanceOf[ArrayType] => + recursivelyGetBufferForArrayType(d.asInstanceOf[ArrayType], key) + }(x => x)((x, y) => (x._1, x._2 + y._2)).values + } + + private def isSpecificStringTypeMatch(field: StructField, fieldName: String): Boolean = + field.dataType.isInstanceOf[StringType] && + !field.dataType.asInstanceOf[StringType].supportsBinaryEquality && Review Comment: ditto -- 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