@@ -32,7 +32,7 @@ use crate::spec::SchemaRef;
3232/// Builder to create ArrowReader
3333pub struct ArrowReaderBuilder {
3434 batch_size : Option < usize > ,
35- column_names : Vec < String > ,
35+ columns : Vec < usize > ,
3636 file_io : FileIO ,
3737 schema : SchemaRef ,
3838}
@@ -42,7 +42,7 @@ impl ArrowReaderBuilder {
4242 pub fn new ( file_io : FileIO , schema : SchemaRef ) -> Self {
4343 ArrowReaderBuilder {
4444 batch_size : None ,
45- column_names : vec ! [ ] ,
45+ columns : vec ! [ ] ,
4646 file_io,
4747 schema,
4848 }
@@ -56,16 +56,16 @@ impl ArrowReaderBuilder {
5656 }
5757
5858 /// Sets the desired column projection.
59- pub fn with_column_projection ( mut self , column_names : Vec < String > ) -> Self {
60- self . column_names = column_names ;
59+ pub fn with_column_projection ( mut self , columns : Vec < usize > ) -> Self {
60+ self . columns = columns ;
6161 self
6262 }
6363
6464 /// Build the ArrowReader.
6565 pub fn build ( self ) -> ArrowReader {
6666 ArrowReader {
6767 batch_size : self . batch_size ,
68- column_names : self . column_names ,
68+ columns : self . columns ,
6969 schema : self . schema ,
7070 file_io : self . file_io ,
7171 }
@@ -75,7 +75,7 @@ impl ArrowReaderBuilder {
7575/// Reads data from Parquet files
7676pub struct ArrowReader {
7777 batch_size : Option < usize > ,
78- column_names : Vec < String > ,
78+ columns : Vec < usize > ,
7979 #[ allow( dead_code) ]
8080 schema : SchemaRef ,
8181 file_io : FileIO ,
@@ -121,23 +121,21 @@ impl ArrowReader {
121121 metadata : & Arc < ParquetMetaData > ,
122122 parquet_schema : & ArrowSchemaRef ,
123123 ) -> crate :: Result < ProjectionMask > {
124- if self . column_names . is_empty ( ) {
124+ if self . columns . is_empty ( ) {
125125 Ok ( ProjectionMask :: all ( ) )
126126 } else {
127127 let mut indices = vec ! [ ] ;
128- for column_name in & self . column_names {
129- match parquet_schema. index_of ( column_name) {
130- Ok ( index) => indices. push ( index) ,
131- Err ( _) => {
132- return Err ( Error :: new (
133- ErrorKind :: DataInvalid ,
134- format ! (
135- "Column {} not found in table. Schema: {}" ,
136- column_name, parquet_schema
137- ) ,
138- ) ) ;
139- }
128+ for col in & self . columns {
129+ if * col > parquet_schema. fields ( ) . len ( ) {
130+ return Err ( Error :: new (
131+ ErrorKind :: DataInvalid ,
132+ format ! (
133+ "Column index {} out of range. Schema: {}" ,
134+ col, parquet_schema
135+ ) ,
136+ ) ) ;
140137 }
138+ indices. push ( * col - 1 ) ;
141139 }
142140 Ok ( ProjectionMask :: roots (
143141 metadata. file_metadata ( ) . schema_descr ( ) ,
0 commit comments