yadavay-amzn commented on code in PR #57241:
URL: https://github.com/apache/spark/pull/57241#discussion_r3584064925


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/percentiles.scala:
##########
@@ -224,7 +224,8 @@ abstract class PercentileBase
       toDoubleValue(lowerKey)
     } else {
       // Linear interpolation to get the exact percentile
-      (higher - position) * toDoubleValue(lowerKey) + (position - lower) * 
toDoubleValue(higherKey)
+      toDoubleValue(lowerKey) +
+        (position - lower) * (toDoubleValue(higherKey) - 
toDoubleValue(lowerKey))

Review Comment:
   Optional, non-blocking. Computing `higher - lower` here can overflow to 
Infinity when the two adjacent keys straddle zero with magnitudes near 
Double.MaxValue (e.g. lower=-9e307, higher=9e307 makes the delta overflow, so 
p50 comes back as Infinity where the old form returned a finite value). It's an 
extremely unlikely input and the old form had its own accuracy issues in that 
range, so I don't think it should block anything. Might be worth a one-line 
comment noting the tradeoff, or nothing at all. Your call.



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