Dandandan commented on code in PR #16433:
URL: https://github.com/apache/datafusion/pull/16433#discussion_r2154078467


##########
datafusion/physical-plan/src/topk/mod.rs:
##########
@@ -319,13 +341,88 @@ impl TopK {
     /// (a > 2 OR (a = 2 AND b < 3))
     /// ```
     fn update_filter(&mut self) -> Result<()> {
-        let Some(filter) = &self.filter else {
-            return Ok(());
-        };
         let Some(thresholds) = self.heap.get_threshold_values(&self.expr)? 
else {
             return Ok(());
         };
 
+        // Are the new thresholds more selective than our existing ones?
+        let should_update = {
+            if let Some(current) = self.filter.thresholds.write().as_mut() {
+                assert!(current.len() == thresholds.len());
+                // Check if new thresholds are more selective than current ones
+                let mut more_selective = false;
+                for ((current_value, new_value), sort_expr) in
+                    current.iter().zip(thresholds.iter()).zip(self.expr.iter())
+                {
+                    // Handle null cases
+                    let (current_is_null, new_is_null) =
+                        (current_value.is_null(), new_value.is_null());

Review Comment:
   Can't we use `ScalarValue::partial_cmp`?



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