TJX2014 commented on a change in pull request #28351:
URL: https://github.com/apache/spark/pull/28351#discussion_r417017373
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/collect.scala
##########
@@ -139,19 +143,27 @@ case class CollectSet(
def this(child: Expression) = this(child, 0, 0)
+ /* SPARK-31500
+ * Array[Byte](BinaryType) Scala equality don't works as expected
+ * so HashSet return duplicates, we have to change types to drop
+ * this duplicates and make collect_set work as expected for this
+ * data type
+ */
+ override lazy val typeChild = child.dataType match {
+ case BinaryType => ArrayType(BinaryType)
+ case other => other
+ }
+
+ override def getValueOnUpdate(value: Any): Any =
InternalRow.copyValue(value) match {
+ case v: Array[Byte] => UnsafeArrayData.fromPrimitiveArray(v)
+ case other => other
+ }
+
override def eval(buffer: mutable.HashSet[Any]): Any = {
- /* SPARK-31500
- * Array[Byte](BinaryType) Scala equality don't works as expected
- * so HashSet return duplicates, we have to change types to drop
- * this duplicates and make collect_set work as expected for this
- * data type
- * */
val bufferUpdated: mutable.HashSet[Any] =
- buffer match {
- case b if b.exists(_.isInstanceOf[Array[Byte]]) =>
- b.map(_.asInstanceOf[Array[Byte]].toSeq)
- .map(_.asInstanceOf[mutable.WrappedArray[Byte]].toArray)
- case other => other
+ child.dataType match {
Review comment:
override def eval(buffer: T): Any = {
val bufferUpdated = {
child.dataType match {
case BinaryType => buffer.map(i => UnsafeArrayData.
fromPrimitiveArray(i.asInstanceOf[Array[Byte]])).toSet
case _ => buffer
}
}
new GenericArrayData(bufferUpdated)
}
maybe could try this may ~, :-)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]