stevomitric commented on code in PR #59781:
URL: https://github.com/apache/spark/pull/59781#discussion_r4390837828


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/percentiles.scala:
##########
@@ -195,12 +209,20 @@ abstract class PercentileBase
    */
   protected def getPercentile(
       accumulatedCounts: Seq[(AnyRef, Long)],
-      percentile: Double): Double = {
+      percentile: Double): Any = {
     val position = (accumulatedCounts.last._2 - 1) * percentile
+    // A double position can land just below a whole number (e.g. 90 * 0.7), 
which flooring a
+    // nanosecond result would turn into a whole step.
+    lazy val exactPosition = JBigDecimal.valueOf(accumulatedCounts.last._2 - 1)
+      .multiply(JBigDecimal.valueOf(percentile))
 

Review Comment:
   fixed - NaN percentage now keeps the double position, so nanos returns the 
first value in sort order like the other types instead of throwing. added tests 
too. Thanks!



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