@@ -276,7 +276,7 @@ struct PushdownChecker<'schema> {
276276 /// Does the expression reference any columns not present in the file schema?
277277 projected_columns : bool ,
278278 /// Indices into the file schema of columns required to evaluate the expression.
279- required_columns : BTreeSet < usize > ,
279+ required_columns : Vec < usize > ,
280280 /// Tracks the nested column behavior found during traversal.
281281 nested_behavior : NestedColumnSupport ,
282282 /// Whether nested list columns are supported by the predicate semantics.
@@ -290,7 +290,7 @@ impl<'schema> PushdownChecker<'schema> {
290290 Self {
291291 non_primitive_columns : false ,
292292 projected_columns : false ,
293- required_columns : BTreeSet :: default ( ) ,
293+ required_columns : Vec :: new ( ) ,
294294 nested_behavior : NestedColumnSupport :: PrimitiveOnly ,
295295 allow_list_columns,
296296 file_schema,
@@ -307,7 +307,9 @@ impl<'schema> PushdownChecker<'schema> {
307307 }
308308 } ;
309309
310- self . required_columns . insert ( idx) ;
310+ if !self . required_columns . contains ( & idx) {
311+ self . required_columns . push ( idx) ;
312+ }
311313 let data_type = self . file_schema . field ( idx) . data_type ( ) ;
312314
313315 if DataType :: is_nested ( data_type) {
@@ -390,9 +392,8 @@ enum NestedColumnSupport {
390392 Unsupported ,
391393}
392394
393- #[ derive( Debug ) ]
394395struct PushdownColumns {
395- required_columns : BTreeSet < usize > ,
396+ required_columns : Vec < usize > ,
396397 nested : NestedColumnSupport ,
397398}
398399
@@ -411,9 +412,13 @@ fn pushdown_columns(
411412 let allow_list_columns = supports_list_predicates ( expr) ;
412413 let mut checker = PushdownChecker :: new ( file_schema, allow_list_columns) ;
413414 expr. visit ( & mut checker) ?;
414- Ok ( ( !checker. prevents_pushdown ( ) ) . then_some ( PushdownColumns {
415- required_columns : checker. required_columns ,
416- nested : checker. nested_behavior ,
415+ let prevents_pushdown = checker. prevents_pushdown ( ) ;
416+ let nested = checker. nested_behavior ;
417+ let mut required_columns = checker. required_columns ;
418+ required_columns. sort_unstable ( ) ;
419+ Ok ( ( !prevents_pushdown) . then_some ( PushdownColumns {
420+ required_columns,
421+ nested,
417422 } ) )
418423}
419424
0 commit comments