1919//! from a Parquet file
2020
2121use crate :: arrow:: array_reader:: ArrayReader ;
22+ use crate :: arrow:: arrow_reader:: selection:: RowSelectionPolicy ;
23+ use crate :: arrow:: arrow_reader:: selection:: RowSelectionStrategy ;
2224use crate :: arrow:: arrow_reader:: {
23- ArrowPredicate , ParquetRecordBatchReader , RowSelection , RowSelectionCursor ,
24- RowSelectionStrategy , RowSelector ,
25+ ArrowPredicate , ParquetRecordBatchReader , RowSelection , RowSelectionCursor , RowSelector ,
2526} ;
2627use crate :: errors:: { ParquetError , Result } ;
2728use arrow_array:: Array ;
@@ -32,10 +33,10 @@ use std::collections::VecDeque;
3233#[ derive( Clone , Debug ) ]
3334pub struct ReadPlanBuilder {
3435 batch_size : usize ,
35- /// Current to apply, includes all filters
36+ /// Which rows to select. Includes the result of all filters applied so far
3637 selection : Option < RowSelection > ,
37- /// Strategy to use when materialising the row selection
38- selection_strategy : RowSelectionStrategy ,
38+ /// Policy to use when materializing the row selection
39+ row_selection_policy : RowSelectionPolicy ,
3940}
4041
4142impl ReadPlanBuilder {
@@ -44,7 +45,7 @@ impl ReadPlanBuilder {
4445 Self {
4546 batch_size,
4647 selection : None ,
47- selection_strategy : RowSelectionStrategy :: default ( ) ,
48+ row_selection_policy : RowSelectionPolicy :: default ( ) ,
4849 }
4950 }
5051
@@ -54,12 +55,19 @@ impl ReadPlanBuilder {
5455 self
5556 }
5657
57- /// Configure the strategy to use when materialising the [`RowSelection`]
58- pub fn with_selection_strategy ( mut self , strategy : RowSelectionStrategy ) -> Self {
59- self . selection_strategy = strategy;
58+ /// Configure the policy to use when materialising the [`RowSelection`]
59+ ///
60+ /// Defaults to [`RowSelectionPolicy::Auto`]
61+ pub fn with_row_selection_policy ( mut self , policy : RowSelectionPolicy ) -> Self {
62+ self . row_selection_policy = policy;
6063 self
6164 }
6265
66+ /// Returns the current row selection policy
67+ pub fn row_selection_policy ( & self ) -> & RowSelectionPolicy {
68+ & self . row_selection_policy
69+ }
70+
6371 /// Returns the current selection, if any
6472 pub fn selection ( & self ) -> Option < & RowSelection > {
6573 self . selection . as_ref ( )
@@ -89,14 +97,14 @@ impl ReadPlanBuilder {
8997 self . selection . as_ref ( ) . map ( |s| s. row_count ( ) )
9098 }
9199
92- /// Returns the preferred [`RowSelectionStrategy`] for materialising the current selection .
100+ /// Returns the [`RowSelectionStrategy`] for this plan .
93101 ///
94102 /// Guarantees to return either `Selectors` or `Mask`, never `Auto`.
95- pub fn preferred_selection_strategy ( & self ) -> RowSelectionStrategy {
96- match self . selection_strategy {
97- RowSelectionStrategy :: Selectors => RowSelectionStrategy :: Selectors ,
98- RowSelectionStrategy :: Mask => RowSelectionStrategy :: Mask ,
99- RowSelectionStrategy :: Auto { threshold, .. } => {
103+ pub ( crate ) fn resolve_selection_strategy ( & self ) -> RowSelectionStrategy {
104+ match self . row_selection_policy {
105+ RowSelectionPolicy :: Selectors => RowSelectionStrategy :: Selectors ,
106+ RowSelectionPolicy :: Mask => RowSelectionStrategy :: Mask ,
107+ RowSelectionPolicy :: Auto { threshold, .. } => {
100108 let selection = match self . selection . as_ref ( ) {
101109 Some ( selection) => selection,
102110 None => return RowSelectionStrategy :: Selectors ,
@@ -172,12 +180,12 @@ impl ReadPlanBuilder {
172180 }
173181
174182 // Preferred strategy must not be Auto
175- let selection_strategy = self . preferred_selection_strategy ( ) ;
183+ let selection_strategy = self . resolve_selection_strategy ( ) ;
176184
177185 let Self {
178186 batch_size,
179187 selection,
180- selection_strategy : _,
188+ row_selection_policy : _,
181189 } = self ;
182190
183191 let selection = selection. map ( |s| s. trim ( ) ) ;
@@ -191,7 +199,6 @@ impl ReadPlanBuilder {
191199 RowSelectionCursor :: new_mask_from_selectors ( selectors)
192200 }
193201 RowSelectionStrategy :: Selectors => RowSelectionCursor :: new_selectors ( selectors) ,
194- RowSelectionStrategy :: Auto { .. } => unreachable ! ( ) ,
195202 }
196203 } )
197204 . unwrap_or ( RowSelectionCursor :: new_all ( ) ) ;
@@ -335,21 +342,18 @@ mod tests {
335342 let selection = RowSelection :: from ( vec ! [ RowSelector :: select( 8 ) ] ) ;
336343 let builder = builder_with_selection ( selection) ;
337344 assert_eq ! (
338- builder. preferred_selection_strategy ( ) ,
345+ builder. resolve_selection_strategy ( ) ,
339346 RowSelectionStrategy :: Mask
340347 ) ;
341348 }
342349
343350 #[ test]
344351 fn preferred_selection_strategy_prefers_selectors_when_threshold_small ( ) {
345352 let selection = RowSelection :: from ( vec ! [ RowSelector :: select( 8 ) ] ) ;
346- let builder =
347- builder_with_selection ( selection) . with_selection_strategy ( RowSelectionStrategy :: Auto {
348- threshold : 1 ,
349- safe_strategy : true ,
350- } ) ;
353+ let builder = builder_with_selection ( selection)
354+ . with_row_selection_policy ( RowSelectionPolicy :: Auto { threshold : 1 } ) ;
351355 assert_eq ! (
352- builder. preferred_selection_strategy ( ) ,
356+ builder. resolve_selection_strategy ( ) ,
353357 RowSelectionStrategy :: Selectors
354358 ) ;
355359 }
0 commit comments