@@ -82,7 +82,6 @@ use tokio::io::AsyncWriteExt;
8282/// ```
8383#[ derive( Debug , Clone , Default ) ]
8484pub struct CsvSource {
85- file_projection : Option < Vec < usize > > ,
8685 pub ( crate ) has_header : bool ,
8786 delimiter : u8 ,
8887 quote : u8 ,
@@ -161,14 +160,18 @@ impl CsvSource {
161160 reader : R ,
162161 file_schema : SchemaRef ,
163162 batch_size : Option < usize > ,
163+ file_column_projection_indices : Option < Vec < usize > > ,
164164 ) -> Result < csv:: Reader < R > > {
165- Ok ( self . builder ( file_schema, batch_size) . build ( reader) ?)
165+ Ok ( self
166+ . builder ( file_schema, batch_size, file_column_projection_indices)
167+ . build ( reader) ?)
166168 }
167169
168170 fn builder (
169171 & self ,
170172 file_schema : SchemaRef ,
171173 batch_size : Option < usize > ,
174+ file_column_projection_indices : Option < Vec < usize > > ,
172175 ) -> csv:: ReaderBuilder {
173176 let mut builder = csv:: ReaderBuilder :: new ( Arc :: clone ( & file_schema) )
174177 . with_delimiter ( self . delimiter )
@@ -180,7 +183,7 @@ impl CsvSource {
180183 if let Some ( terminator) = self . terminator {
181184 builder = builder. with_terminator ( terminator) ;
182185 }
183- if let Some ( proj) = & self . file_projection {
186+ if let Some ( proj) = & file_column_projection_indices {
184187 builder = builder. with_projection ( proj. clone ( ) ) ;
185188 }
186189 if let Some ( escape) = self . escape {
@@ -199,8 +202,11 @@ pub struct CsvOpener {
199202 source : Arc < CsvSource > ,
200203 file_compression_type : FileCompressionType ,
201204 object_store : Arc < dyn ObjectStore > ,
205+
206+ // matthew remove and use source.config
202207 file_schema : SchemaRef ,
203208 batch_size : Option < usize > ,
209+ file_column_projection_indices : Option < Vec < usize > > ,
204210}
205211
206212impl CsvOpener {
@@ -213,13 +219,15 @@ impl CsvOpener {
213219 // matthew: delete this and use source.config
214220 file_schema : SchemaRef ,
215221 batch_size : Option < usize > ,
222+ file_column_projection_indices : Option < Vec < usize > > ,
216223 ) -> Self {
217224 Self {
218225 source,
219226 file_compression_type,
220227 object_store,
221228 file_schema,
222229 batch_size,
230+ file_column_projection_indices,
223231 }
224232 }
225233}
@@ -243,19 +251,14 @@ impl FileSource for CsvSource {
243251 object_store,
244252 file_schema : base_config. file_schema . clone ( ) ,
245253 batch_size : base_config. batch_size ,
254+ file_column_projection_indices : base_config. file_column_projection_indices ( ) ,
246255 } )
247256 }
248257
249258 fn as_any ( & self ) -> & dyn Any {
250259 self
251260 }
252261
253- fn with_projection ( & self , config : & FileScanConfig ) -> Arc < dyn FileSource > {
254- let mut conf = self . clone ( ) ;
255- conf. file_projection = config. file_column_projection_indices ( ) ;
256- Arc :: new ( conf)
257- }
258-
259262 fn metrics ( & self ) -> & ExecutionPlanMetricsSet {
260263 & self . metrics
261264 }
@@ -350,6 +353,7 @@ impl FileOpener for CsvOpener {
350353
351354 let file_schema = Arc :: clone ( & self . file_schema ) ;
352355 let batch_size = self . batch_size ;
356+ let file_column_projection_indices = self . file_column_projection_indices . clone ( ) ;
353357
354358 Ok ( Box :: pin ( async move {
355359 // Current partition contains bytes [start_byte, end_byte) (might contain incomplete lines at boundaries)
@@ -392,11 +396,14 @@ impl FileOpener for CsvOpener {
392396 decoder,
393397 file_schema,
394398 batch_size,
399+ file_column_projection_indices,
395400 ) ?)
396401 . boxed ( ) )
397402 }
398403 GetResultPayload :: Stream ( s) => {
399- let decoder = source. builder ( file_schema, batch_size) . build_decoder ( ) ;
404+ let decoder = source
405+ . builder ( file_schema, batch_size, file_column_projection_indices)
406+ . build_decoder ( ) ;
400407 let s = s. map_err ( DataFusionError :: from) ;
401408 let input = file_compression_type. convert_stream ( s. boxed ( ) ) ?. fuse ( ) ;
402409
0 commit comments