Skip to content

Commit debb2fb

Browse files
committed
code cleanup
1 parent 6c3b7e2 commit debb2fb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

rust/arrow/src/datatypes.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)