diff --git a/rust/arrow/src/datatypes.rs b/rust/arrow/src/datatypes.rs index 34860350e7357..e0b6d706eab15 100644 --- a/rust/arrow/src/datatypes.rs +++ b/rust/arrow/src/datatypes.rs @@ -26,7 +26,6 @@ use std::mem::size_of; use std::ops::{Add, Div, Mul, Sub}; use std::slice::from_raw_parts; use std::str::FromStr; -use std::sync::Arc; use packed_simd::*; use serde_derive::{Deserialize, Serialize}; @@ -752,22 +751,6 @@ impl Schema { "fields": self.fields.iter().map(|field| field.to_json()).collect::>(), }) } - - /// Create a new schema by applying a projection to this schema's fields - pub fn projection(&self, projection: &[usize]) -> Result> { - let mut fields: Vec = Vec::with_capacity(projection.len()); - for i in projection { - if *i < self.fields().len() { - fields.push(self.field(*i).clone()); - } else { - return Err(ArrowError::InvalidArgumentError(format!( - "Invalid column index {} in projection", - i - ))); - } - } - Ok(Arc::new(Schema::new(fields))) - } } impl fmt::Display for Schema { diff --git a/rust/datafusion/src/datasource/parquet.rs b/rust/datafusion/src/datasource/parquet.rs index 74cc813ba06d5..efb1857be9b8f 100644 --- a/rust/datafusion/src/datasource/parquet.rs +++ b/rust/datafusion/src/datasource/parquet.rs @@ -208,7 +208,7 @@ impl ParquetFile { } }; - let projected_schema = schema.projection(&projection)?; + let projected_schema = schema_projection(&schema, &projection)?; Ok(ParquetFile { reader: reader, @@ -337,6 +337,22 @@ impl ParquetFile { } } +/// Create a new schema by applying a projection to this schema's fields +fn schema_projection(schema: &Schema, projection: &[usize]) -> Result> { + let mut fields: Vec = Vec::with_capacity(projection.len()); + for i in projection { + if *i < schema.fields().len() { + fields.push(schema.field(*i).clone()); + } else { + return Err(ExecutionError::InvalidColumn(format!( + "Invalid column index {} in projection", + i + ))); + } + } + Ok(Arc::new(Schema::new(fields))) +} + /// convert a Parquet INT96 to an Arrow timestamp in nanoseconds fn convert_int96_timestamp(v: &[u32]) -> i64 { const JULIAN_DAY_OF_EPOCH: i64 = 2_440_588;