Skip to content

Commit fb87e2c

Browse files
committed
Use Vec instead of VecDeque
1 parent 948374a commit fb87e2c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

parquet/src/arrow/arrow_reader/read_plan.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use crate::arrow::arrow_reader::{
2525
use crate::errors::{ParquetError, Result};
2626
use arrow_array::Array;
2727
use arrow_select::filter::prep_null_mask_filter;
28-
use std::collections::VecDeque;
2928

3029
/// A builder for [`ReadPlan`]
3130
#[derive(Clone)]
@@ -162,14 +161,19 @@ pub(crate) struct SelectionIterator {
162161
/// how many records have been read by RowSelection in the "current" batch
163162
read_records: usize,
164163
/// Input selectors to read from
165-
input_selectors: VecDeque<RowSelector>,
164+
input_selectors: Vec<RowSelector>,
165+
/// index into `input_selectors` of the next selector to read
166+
index: usize,
166167
}
167168

168169
impl Iterator for SelectionIterator {
169170
type Item = RowSelector;
170171

171172
fn next(&mut self) -> Option<Self::Item> {
172-
while let Some(mut front) = self.input_selectors.pop_front() {
173+
while self.index < self.input_selectors.len() {
174+
let mut front = self.input_selectors[self.index];
175+
self.index += 1;
176+
173177
// RowSelectors with row_count = 0 terminate the read, so skip such
174178
// entries. See https://github.com/apache/arrow-rs/issues/2669
175179
if front.row_count == 0 {
@@ -187,8 +191,8 @@ impl Iterator for SelectionIterator {
187191
if front.row_count > need_read {
188192
// Part 1: return remaining rows to the front of the queue
189193
let remaining = front.row_count - need_read;
190-
self.input_selectors
191-
.push_front(RowSelector::select(remaining));
194+
self.index -= 1;
195+
self.input_selectors[self.index] = RowSelector::select(remaining);
192196
// Part 2: adjust the current selector to read the rows we need
193197
front.row_count = need_read;
194198
}
@@ -207,16 +211,17 @@ impl Iterator for SelectionIterator {
207211
}
208212

209213
impl SelectionIterator {
210-
fn new(batch_size: usize, mut input_selectors: VecDeque<RowSelector>) -> Self {
214+
fn new(batch_size: usize, mut input_selectors: Vec<RowSelector>) -> Self {
211215
// trim any trailing empty selectors
212-
while input_selectors.back().map(|x| x.skip).unwrap_or(false) {
213-
input_selectors.pop_back();
216+
while input_selectors.last().map(|x| x.skip).unwrap_or(false) {
217+
input_selectors.pop();
214218
}
215219

216220
Self {
217221
batch_size,
218222
read_records: 0,
219223
input_selectors,
224+
index: 0,
220225
}
221226
}
222227

0 commit comments

Comments
 (0)