Skip to content

Commit 8d2df06

Browse files
committed
move schema projection function from arrow into datafusion
1 parent 204db83 commit 8d2df06

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

rust/arrow/src/datatypes.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use std::mem::size_of;
2626
use std::ops::{Add, Div, Mul, Sub};
2727
use std::slice::from_raw_parts;
2828
use std::str::FromStr;
29-
use std::sync::Arc;
3029

3130
use packed_simd::*;
3231
use serde_derive::{Deserialize, Serialize};
@@ -752,22 +751,6 @@ impl Schema {
752751
"fields": self.fields.iter().map(|field| field.to_json()).collect::<Vec<Value>>(),
753752
})
754753
}
755-
756-
/// Create a new schema by applying a projection to this schema's fields
757-
pub fn projection(&self, projection: &[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-
}
769-
Ok(Arc::new(Schema::new(fields)))
770-
}
771754
}
772755

773756
impl fmt::Display for Schema {

rust/datafusion/src/datasource/parquet.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl ParquetFile {
208208
}
209209
};
210210

211-
let projected_schema = schema.projection(&projection)?;
211+
let projected_schema = schema_projection(&schema, &projection)?;
212212

213213
Ok(ParquetFile {
214214
reader: reader,
@@ -337,6 +337,22 @@ impl ParquetFile {
337337
}
338338
}
339339

340+
/// Create a new schema by applying a projection to this schema's fields
341+
fn schema_projection(schema: &Schema, projection: &[usize]) -> Result<Arc<Schema>> {
342+
let mut fields: Vec<Field> = Vec::with_capacity(projection.len());
343+
for i in projection {
344+
if *i < schema.fields().len() {
345+
fields.push(schema.field(*i).clone());
346+
} else {
347+
return Err(ExecutionError::InvalidColumn(format!(
348+
"Invalid column index {} in projection",
349+
i
350+
)));
351+
}
352+
}
353+
Ok(Arc::new(Schema::new(fields)))
354+
}
355+
340356
/// convert a Parquet INT96 to an Arrow timestamp in nanoseconds
341357
fn convert_int96_timestamp(v: &[u32]) -> i64 {
342358
const JULIAN_DAY_OF_EPOCH: i64 = 2_440_588;

0 commit comments

Comments
 (0)