Skip to content

Apache DataFusion SQL Query Engine

Remove batch_idx from SortKeyCursor (#5855)

Raphael Taylor-Davies56a5adcff1d6
diff --git a/datafusion/core/src/physical_plan/sorts/cursor.rs b/datafusion/core/src/physical_plan/sorts/cursor.rs
index 53df698c33..e52544cf50 100644
--- a/datafusion/core/src/physical_plan/sorts/cursor.rs
+++ b/datafusion/core/src/physical_plan/sorts/cursor.rs
@@ -32,9 +32,6 @@ pub struct SortKeyCursor {
cur_row: usize,
num_rows: usize,
- // An id uniquely identifying the record batch scanned by this cursor.
- batch_id: usize,
-
rows: Rows,
}
@@ -43,19 +40,17 @@ impl std::fmt::Debug for SortKeyCursor {
f.debug_struct("SortKeyCursor")
.field("cur_row", &self.cur_row)
.field("num_rows", &self.num_rows)
- .field("batch_id", &self.batch_id)
.finish()
}
}
impl SortKeyCursor {
/// Create a new SortKeyCursor
- pub fn new(stream_idx: usize, batch_id: usize, rows: Rows) -> Self {
+ pub fn new(stream_idx: usize, rows: Rows) -> Self {
Self {
stream_idx,
cur_row: 0,
num_rows: rows.num_rows(),
- batch_id,
rows,
}
}
@@ -66,12 +61,6 @@ impl SortKeyCursor {
self.stream_idx
}
- #[inline(always)]
- /// Return the batch id of this cursor
- pub fn batch_id(&self) -> usize {
- self.batch_id
- }
-
#[inline(always)]
/// Return true if the stream is finished
pub fn is_finished(&self) -> bool {
diff --git a/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs b/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs
index edacae4052..14204ef3b4 100644
--- a/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs
+++ b/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs
@@ -318,9 +318,6 @@ pub(crate) struct SortPreservingMergeStream {
/// If the stream has encountered an error
aborted: bool,
- /// An id to uniquely identify the input stream batch
- next_batch_id: usize,
-
/// Vector that holds all [`SortKeyCursor`]s
cursors: Vec<Option<SortKeyCursor>>,
@@ -381,7 +378,6 @@ impl SortPreservingMergeStream {
tracking_metrics,
aborted: false,
in_progress: vec![],
- next_batch_id: 0,
cursors: (0..stream_count).map(|_| None).collect(),
loser_tree: Vec::with_capacity(stream_count),
loser_tree_adjusted: false,
@@ -436,12 +432,7 @@ impl SortPreservingMergeStream {
}
};
- self.cursors[idx] = Some(SortKeyCursor::new(
- idx,
- self.next_batch_id, // assign this batch an ID
- rows,
- ));
- self.next_batch_id += 1;
+ self.cursors[idx] = Some(SortKeyCursor::new(idx, rows));
self.batches[idx].push_back(batch)
} else {
empty_batch = true;
diff --git a/datafusion/core/tests/sort_key_cursor.rs b/datafusion/core/tests/sort_key_cursor.rs
index 7d03ffc87b..0ae641bfb6 100644
--- a/datafusion/core/tests/sort_key_cursor.rs
+++ b/datafusion/core/tests/sort_key_cursor.rs
@@ -32,12 +32,10 @@ fn test_single_column() {
let mut cursor1 = CursorBuilder::new(batch1)
.with_stream_idx(11)
- .with_batch_id(0)
.build(&mut converter);
let mut cursor2 = CursorBuilder::new(batch2)
.with_stream_idx(22)
- .with_batch_id(0)
.build(&mut converter);
let expected = vec![
@@ -63,13 +61,11 @@ fn test_stable_compare() {
let cursor1 = CursorBuilder::new(batch1)
// higher stream index
- .with_stream_idx(33)
- .with_batch_id(0);
+ .with_stream_idx(33);
let cursor2 = CursorBuilder::new(batch2)
// Lower stream index -- should always be first
- .with_stream_idx(22)
- .with_batch_id(0);
+ .with_stream_idx(22);
let expected = vec!["22: (0, 0)", "33: (0, 0)", "33: (0, 1)"];
@@ -127,7 +123,7 @@ fn advance(cursor: &mut SortKeyCursor) -> RowIndex {
let row_idx = cursor.advance();
RowIndex {
stream_idx: cursor.stream_idx(),
- batch_idx: cursor.batch_id(),
+ batch_idx: 0,
row_idx,
}
}
@@ -152,7 +148,6 @@ fn int64_batch(values: impl IntoIterator<Item = Option<i64>>) -> RecordBatch {
struct CursorBuilder {
batch: RecordBatch,
stream_idx: Option<usize>,
- batch_id: Option<usize>,
}
impl CursorBuilder {
@@ -160,7 +155,6 @@ impl CursorBuilder {
Self {
batch,
stream_idx: None,
- batch_id: None,
}
}
@@ -170,24 +164,10 @@ impl CursorBuilder {
self
}
- /// Set the stream index
- fn with_batch_id(mut self, batch_id: usize) -> Self {
- self.batch_id = Some(batch_id);
- self
- }
-
fn build(self, converter: &mut RowConverter) -> SortKeyCursor {
- let Self {
- batch,
- stream_idx,
- batch_id,
- } = self;
+ let Self { batch, stream_idx } = self;
let rows = converter.convert_columns(batch.columns()).unwrap();
- SortKeyCursor::new(
- stream_idx.expect("stream idx not set"),
- batch_id.expect("batch id not set"),
- rows,
- )
+ SortKeyCursor::new(stream_idx.expect("stream idx not set"), rows)
}
}