zhangfengcdt commented on code in PR #6928:
URL: https://github.com/apache/datafusion-comet/pull/6928#discussion_r4259986541


##########
native/spark-expr/src/agg_funcs/percentile.rs:
##########
@@ -285,46 +321,228 @@ impl GroupsAccumulator for 
SparkPercentileGroupsAccumulator {
             .map(|values| values.capacity() * size_of::<f64>())
             .sum::<usize>()
             + self.group_values.capacity() * size_of::<Vec<f64>>()
+            + self
+                .group_partial_ends
+                .iter()
+                .map(|ends| ends.capacity() * size_of::<usize>())
+                .sum::<usize>()
+            + self.group_partial_ends.capacity() * size_of::<Vec<usize>>()
     }
 }
 
-fn spark_percentile(values: &mut [f64], percentile: f64) -> Option<f64> {
+/// `partial_ends` marks where each partial state merged into `values` ends. 
Values past the last
+/// one came straight from input rows, as in Spark's `Complete` mode.
+fn spark_percentile(
+    values: &mut [f64],
+    partial_ends: &[usize],
+    percentile: f64,
+    float_input: bool,
+) -> Option<f64> {
     let len = values.len();
     if len == 0 {
         return None;
     }
     if len == 1 {
         return Some(values[0]);
     }
+    // Read before the selection below reorders the values.
+    let zeros = SignedZeros::find(values, partial_ends, float_input);

Review Comment:
   Done! Now, the ranks are computed first and the replay only runs upon 
failures on a zero. A median or maximum away from zero can skip it.



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