@@ -25,7 +25,6 @@ use crate::arrow::arrow_reader::{
25
25
use crate :: errors:: { ParquetError , Result } ;
26
26
use arrow_array:: Array ;
27
27
use arrow_select:: filter:: prep_null_mask_filter;
28
- use std:: collections:: VecDeque ;
29
28
30
29
/// A builder for [`ReadPlan`]
31
30
#[ derive( Clone ) ]
@@ -162,14 +161,19 @@ pub(crate) struct SelectionIterator {
162
161
/// how many records have been read by RowSelection in the "current" batch
163
162
read_records : usize ,
164
163
/// 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 ,
166
167
}
167
168
168
169
impl Iterator for SelectionIterator {
169
170
type Item = RowSelector ;
170
171
171
172
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
+
173
177
// RowSelectors with row_count = 0 terminate the read, so skip such
174
178
// entries. See https://github.com/apache/arrow-rs/issues/2669
175
179
if front. row_count == 0 {
@@ -187,8 +191,8 @@ impl Iterator for SelectionIterator {
187
191
if front. row_count > need_read {
188
192
// Part 1: return remaining rows to the front of the queue
189
193
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) ;
192
196
// Part 2: adjust the current selector to read the rows we need
193
197
front. row_count = need_read;
194
198
}
@@ -207,16 +211,17 @@ impl Iterator for SelectionIterator {
207
211
}
208
212
209
213
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 {
211
215
// 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 ( ) ;
214
218
}
215
219
216
220
Self {
217
221
batch_size,
218
222
read_records : 0 ,
219
223
input_selectors,
224
+ index : 0 ,
220
225
}
221
226
}
222
227
0 commit comments