Function datafusion_common::utils::project_schema
source · pub fn project_schema(
schema: &SchemaRef,
projection: Option<&Vec<usize>>
) -> Result<SchemaRef>
Expand description
Applies an optional projection to a [SchemaRef
], returning the
projected schema
Example:
use arrow::datatypes::{SchemaRef, Schema, Field, DataType};
use datafusion_common::project_schema;
// Schema with columns 'a', 'b', and 'c'
let schema = SchemaRef::new(Schema::new(vec![
Field::new("a", DataType::Int32, true),
Field::new("b", DataType::Int64, true),
Field::new("c", DataType::Utf8, true),
]));
// Pick columns 'c' and 'b'
let projection = Some(vec![2,1]);
let projected_schema = project_schema(
&schema,
projection.as_ref()
).unwrap();
let expected_schema = SchemaRef::new(Schema::new(vec![
Field::new("c", DataType::Utf8, true),
Field::new("b", DataType::Int64, true),
]));
assert_eq!(projected_schema, expected_schema);