Use the DataFrame API to: 1. Read in-memory data.
(ctx: &SessionContext)
| 158 | /// Use the DataFrame API to: |
| 159 | /// 1. Read in-memory data. |
| 160 | async 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. |
no test coverage detected
searching dependent graphs…