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

Function read_memory

datafusion-examples/examples/dataframe/dataframe.rs:160–178  ·  view source on GitHub ↗

Use the DataFrame API to: 1. Read in-memory data.

(ctx: &SessionContext)

Source from the content-addressed store, hash-verified

158/// Use the DataFrame API to:
159/// 1. Read in-memory data.
160async fn read_memory(ctx: &SessionContext) -> Result<()> {
161 // define data in memory
162 let a: ArrayRef = Arc::new(StringArray::from(vec!["a", "b", "c", "d"]));
163 let b: ArrayRef = Arc::new(Int32Array::from(vec![1, 10, 10, 100]));
164 let batch = RecordBatch::try_from_iter(vec![("a", a), ("b", b)])?;
165
166 // declare a table in memory. In Apache Spark API, this corresponds to createDataFrame(...).
167 ctx.register_batch("t", batch)?;
168 let df = ctx.table("t").await?;
169
170 // construct an expression corresponding to "SELECT a, b FROM t WHERE b = 10" in SQL
171 let filter = col("b").eq(lit(10));
172 let df = df.select_columns(&["a", "b"])?.filter(filter)?;
173
174 // print the results
175 df.show().await?;
176
177 Ok(())
178}
179
180/// Use the DataFrame API to:
181/// 1. Read in-memory data.

Callers 1

dataframe_exampleFunction · 0.85

Calls 9

newFunction · 0.85
select_columnsMethod · 0.80
showMethod · 0.80
colFunction · 0.50
litFunction · 0.50
register_batchMethod · 0.45
tableMethod · 0.45
eqMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…