Applies an optional projection to a [`SchemaRef`], returning the projected schema Example: ``` use arrow::datatypes::{DataType, Field, Schema, SchemaRef}; 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)
(
schema: &SchemaRef,
projection: Option<&impl AsRef<[usize]>>,
)
| 80 | /// assert_eq!(projected_schema, expected_schema); |
| 81 | /// ``` |
| 82 | pub fn project_schema( |
| 83 | schema: &SchemaRef, |
| 84 | projection: Option<&impl AsRef<[usize]>>, |
| 85 | ) -> Result<SchemaRef> { |
| 86 | let schema = match projection { |
| 87 | Some(columns) => Arc::new(schema.project(columns.as_ref())?), |
| 88 | None => Arc::clone(schema), |
| 89 | }; |
| 90 | Ok(schema) |
| 91 | } |
| 92 | |
| 93 | /// Extracts a row at the specified index from a set of columns and stores it in the provided buffer. |
| 94 | pub fn extract_row_at_idx_to_buf( |
searching dependent graphs…