File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -754,9 +754,18 @@ impl Schema {
754754 }
755755
756756 /// Create a new schema by applying a projection to this schema's fields
757- pub fn projection ( & self , i : & Vec < usize > ) -> Result < Arc < Schema > > {
758- //TODO bounds checks
759- let fields = i. iter ( ) . map ( |index| self . field ( * index) . clone ( ) ) . collect ( ) ;
757+ pub fn projection ( & self , projection : & Vec < usize > ) -> Result < Arc < Schema > > {
758+ let mut fields: Vec < Field > = Vec :: with_capacity ( projection. len ( ) ) ;
759+ for i in projection {
760+ if * i < self . fields ( ) . len ( ) {
761+ fields. push ( self . field ( * i) . clone ( ) ) ;
762+ } else {
763+ return Err ( ArrowError :: InvalidArgumentError ( format ! (
764+ "Invalid column index {} in projection" ,
765+ i
766+ ) ) ) ;
767+ }
768+ }
760769 Ok ( Arc :: new ( Schema :: new ( fields) ) )
761770 }
762771}
You can’t perform that action at this time.
0 commit comments