Skip to content

Commit f2150dd

Browse files
committed
fmt
1 parent 2aaee6c commit f2150dd

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

datafusion/physical-plan/src/sorts/sort.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,10 @@ impl SortExec {
914914
.iter()
915915
.map(|sort_expr| Arc::clone(&sort_expr.expr))
916916
.collect::<Vec<_>>();
917-
TopKDynamicFilters::new(Arc::new(DynamicFilterPhysicalExpr::new(children, lit(true))))
917+
TopKDynamicFilters::new(Arc::new(DynamicFilterPhysicalExpr::new(
918+
children,
919+
lit(true),
920+
)))
918921
}
919922

920923
fn cloned(&self) -> Self {

datafusion/physical-plan/src/topk/mod.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
//! TopK: Combination of Sort / LIMIT
1919
20+
use arc_swap::ArcSwapOption;
2021
use arrow::{
2122
array::{Array, AsArray},
2223
compute::{interleave_record_batch, prep_null_mask_filter, FilterBuilder},
2324
row::{RowConverter, Rows, SortField},
2425
};
2526
use datafusion_expr::{ColumnarValue, Operator};
26-
use arc_swap::ArcSwapOption;
2727
use std::mem::size_of;
2828
use std::{cmp::Ordering, collections::BinaryHeap, sync::Arc};
2929

@@ -375,24 +375,28 @@ impl TopK {
375375
let new_threshold_arc = Arc::new(new_threshold_row.to_vec());
376376

377377
// Atomically update the threshold using compare-and-swap
378-
let old_threshold = self.filter.threshold_row.compare_and_swap(&current_threshold, Some(Arc::clone(&new_threshold_arc)));
379-
378+
let old_threshold = self.filter.threshold_row.compare_and_swap(
379+
&current_threshold,
380+
Some(Arc::clone(&new_threshold_arc)),
381+
);
382+
380383
// Only update filter if we successfully updated the threshold
381384
// (or if there was no previous threshold and we're the first)
382-
let should_update_filter = match (old_threshold.as_ref(), current_threshold.as_ref()) {
383-
// We successfully swapped
384-
(Some(old), Some(expected)) if Arc::ptr_eq(old, expected) => true,
385-
// We were the first to set it
386-
(None, None) => true,
387-
// Another thread updated before us, check if our threshold is still better
388-
(Some(actual_old), _) => {
389-
actual_old.as_slice().cmp(new_threshold_row) == Ordering::Greater
390-
}
391-
_ => false,
392-
};
385+
let should_update_filter =
386+
match (old_threshold.as_ref(), current_threshold.as_ref()) {
387+
// We successfully swapped
388+
(Some(old), Some(expected)) if Arc::ptr_eq(old, expected) => true,
389+
// We were the first to set it
390+
(None, None) => true,
391+
// Another thread updated before us, check if our threshold is still better
392+
(Some(actual_old), _) => {
393+
actual_old.as_slice().cmp(new_threshold_row) == Ordering::Greater
394+
}
395+
_ => false,
396+
};
393397

394398
if should_update_filter {
395-
// Update the filter expression
399+
// Update the filter expression
396400
if let Some(pred) = predicate {
397401
if !pred.eq(&lit(true)) {
398402
filter_expr.update(pred)?;

0 commit comments

Comments
 (0)