xuzifu666 commented on code in PR #5095:
URL: https://github.com/apache/calcite/pull/5095#discussion_r3575929233


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -4059,6 +4054,54 @@ public static BigDecimal mod(BigDecimal b0, BigDecimal 
b1) {
     return bigDecimals[1];
   }
 
+  // PERCENTILE_CONT / PERCENTILE_DISC
+
+  /** Support the PERCENTILE_CONT aggregate function.
+   *
+   * <p>The {@code values} list must already be sorted according to the
+   * {@code WITHIN GROUP (ORDER BY ...)} clause. The fraction must be in the
+   * range 0 to 1 inclusive. The result is a linear interpolation between the
+   * two values that surround the desired position. */
+  public static double percentileCont(List<? extends Number> values,
+      double fraction) {
+    final int n = values.size();
+    if (n == 0) {
+      throw new NoSuchElementException(
+          "PERCENTILE_CONT is not defined on an empty group");
+    }
+    final double rank = fraction * (n - 1);
+    final int lo = (int) Math.floor(rank);
+    final int hi = (int) Math.ceil(rank);
+    final double loValue = values.get(lo).doubleValue();

Review Comment:
   Makes sense. I’ve updated the handling logic to use BigDecimal instead of 
double.



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

Reply via email to