Skip to content

Commit

Permalink
move schema projection function from arrow into datafusion
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Mar 15, 2019
1 parent 204db83 commit 8d2df06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
17 changes: 0 additions & 17 deletions rust/arrow/src/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -752,22 +751,6 @@ impl Schema {
"fields": self.fields.iter().map(|field| field.to_json()).collect::<Vec<Value>>(),
})
}

/// Create a new schema by applying a projection to this schema's fields
pub fn projection(&self, projection: &[usize]) -> Result<Arc<Schema>> {
let mut fields: Vec<Field> = 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 {
Expand Down
18 changes: 17 additions & 1 deletion rust/datafusion/src/datasource/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl ParquetFile {
}
};

let projected_schema = schema.projection(&projection)?;
let projected_schema = schema_projection(&schema, &projection)?;

Ok(ParquetFile {
reader: reader,
Expand Down Expand Up @@ -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<Arc<Schema>> {
let mut fields: Vec<Field> = 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;
Expand Down

0 comments on commit 8d2df06

Please sign in to comment.