MCPcopy Create free account
hub / github.com/apache/datafusion / from_columns

Method from_columns

datafusion/core/src/dataframe/mod.rs:2570–2586  ·  view source on GitHub ↗

Helper for creating DataFrame. # Example ``` use arrow::array::{ArrayRef, Int32Array, StringArray}; use datafusion::prelude::DataFrame; use std::sync::Arc; let id: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3])); let name: ArrayRef = Arc::new(StringArray::from(vec!["foo", "bar", "baz"])); let df = DataFrame::from_columns(vec![("id", id), ("name", name)]).unwrap(); // +----+------+, // | id |

(columns: Vec<(&str, ArrayRef)>)

Source from the content-addressed store, hash-verified

2568 /// // +----+------+,
2569 /// ```
2570 pub fn from_columns(columns: Vec<(&str, ArrayRef)>) -> Result<Self> {
2571 let fields = columns
2572 .iter()
2573 .map(|(name, array)| Field::new(*name, array.data_type().clone(), true))
2574 .collect::<Vec<_>>();
2575
2576 let arrays = columns
2577 .into_iter()
2578 .map(|(_, array)| array)
2579 .collect::<Vec<_>>();
2580
2581 let schema = Arc::new(Schema::new(fields));
2582 let batch = RecordBatch::try_new(schema, arrays)?;
2583 let ctx = SessionContext::new();
2584 let df = ctx.read_batch(batch)?;
2585 Ok(df)
2586 }
2587}
2588
2589/// Macro for creating DataFrame.

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
read_batchMethod · 0.80
mapMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
data_typeMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected