@@ -39,7 +39,7 @@ use object_store::ObjectStore;
3939pub struct AvroSource {
4040 schema : Option < SchemaRef > ,
4141 batch_size : Option < usize > ,
42- projection : Option < Vec < String > > ,
42+ file_projection : Option < Vec < usize > > ,
4343 metrics : ExecutionPlanMetricsSet ,
4444 projected_statistics : Option < Statistics > ,
4545 schema_adapter_factory : Option < Arc < dyn SchemaAdapterFactory > > ,
@@ -52,16 +52,24 @@ impl AvroSource {
5252 }
5353
5454 fn open < R : std:: io:: BufRead > ( & self , reader : R ) -> Result < Reader < R > > {
55- let avro_schema = AvroSchema :: try_from (
56- self . schema
57- . as_ref ( )
58- . expect ( "Schema must set before open" )
59- . as_ref ( ) ,
60- ) ?;
55+ let schema = self
56+ . schema
57+ . as_ref ( )
58+ . expect ( "Schema must set before open" )
59+ . as_ref ( ) ;
60+
61+ let projected_schema = if let Some ( projection) = & self . file_projection {
62+ & schema. project ( projection) ?
63+ } else {
64+ schema
65+ } ;
66+
67+ let avro_schema = AvroSchema :: try_from ( projected_schema) ?;
68+
6169 ReaderBuilder :: new ( )
6270 . with_reader_schema ( avro_schema) // Used for projection on read.
6371 . with_batch_size ( self . batch_size . expect ( "Batch size must set before open" ) )
64- . build ( reader) // TODO - A File (which doesn't implement BufRead) is being passed; confirm whether this is safe.
72+ . build ( reader)
6573 . map_err ( Into :: into)
6674 }
6775}
@@ -102,7 +110,7 @@ impl FileSource for AvroSource {
102110
103111 fn with_projection ( & self , config : & FileScanConfig ) -> Arc < dyn FileSource > {
104112 let mut conf = self . clone ( ) ;
105- conf. projection = config. projected_file_column_names ( ) ;
113+ conf. file_projection = config. file_column_projection_indices ( ) ;
106114 Arc :: new ( conf)
107115 }
108116
0 commit comments