comphead commented on code in PR #13410:
URL: https://github.com/apache/datafusion/pull/13410#discussion_r1842475353
##########
datafusion-examples/examples/dataframe.rs:
##########
@@ -112,6 +104,38 @@ async fn example_read_csv_file_with_schema(file_path:
&str) -> DataFrame {
schema: Some(&schema),
..Default::default()
};
- // Register a lazy DataFrame by using the context and option provider
- ctx.read_csv(file_path, csv_read_option).await.unwrap()
+ let csv_df = ctx.read_csv(file_path, csv_read_option).await?;
+ csv_df.show().await?;
+
+ // You can also create DataFrames from the result of sql queries
+ // and using the `enable_url_table` refer to local files directly
+ let dyn_ctx = ctx.clone().enable_url_table();
+ let csv_df = dyn_ctx
+ .sql(&format!("SELECT rating, unixtime FROM '{}'", file_path))
+ .await?;
+ csv_df.show().await?;
+
+ Ok(())
+}
+
+/// Use the DataFrame API to:
+/// 1. Read in-memory data.
+async fn read_memory(ctx: &SessionContext) -> Result<()> {
+ // define data in memory
+ let a: ArrayRef = Arc::new(StringArray::from(vec!["a", "b", "c", "d"]));
+ let b: ArrayRef = Arc::new(Int32Array::from(vec![1, 10, 10, 100]));
+ let batch = RecordBatch::try_from_iter(vec![("a", a), ("b", b)])?;
+
+ // declare a table in memory. In spark API, this corresponds to
createDataFrame(...).
Review Comment:
```suggestion
// declare a table in memory. In Apache Spark API, this corresponds to
createDataFrame(...).
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]