cloud-fan commented on code in PR #56360:
URL: https://github.com/apache/spark/pull/56360#discussion_r3376309748


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/collect.scala:
##########
@@ -222,13 +225,26 @@ case class CollectSet(
     buffer
   }
 
+  @transient private lazy val complexNormalizer: Any => Any = {
+    val ref = BoundReference(0, child.dataType, nullable = true)
+    val proj = UnsafeProjection.create(NormalizeFloatingNumbers.normalize(ref))
+    (value: Any) => InternalRow.copyValue(proj(InternalRow(value)).get(0, 
child.dataType))
+  }
+
   override def convertToBufferElement(value: Any): Any = child.dataType match {
     /*
      * collect_set() of BinaryType should not return duplicate elements,
      * Java byte arrays use referential equality and identity hash codes
      * so we need to use a different catalyst value for arrays
      */
     case BinaryType => 
UnsafeArrayData.fromPrimitiveArray(value.asInstanceOf[Array[Byte]])
+    case DoubleType =>
+      java.lang.Double.doubleToLongBits(

Review Comment:
   Consider adding a short comment here (and on the `bufferElementType` remap 
above) mirroring the `BinaryType` note. The reason scalar float/double key on 
the *bit pattern* rather than the value is non-obvious: `mutable.HashSet[Any]` 
compares boxed `Double`/`Float` with IEEE equality, where `NaN != NaN`, so 
normalizing the value alone wouldn't collapse NaNs — keying on 
`doubleToLongBits`/`floatToIntBits` does (and the `NORMALIZER` step keeps 
`-0.0`/`0.0` deduped). Complex types instead dedup on a normalized 
`UnsafeRow`'s binary form. A line or two would save the next reader the trace. 
Non-blocking.



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

Reply via email to