You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/25 13:09:50 UTC

[GitHub] [arrow-datafusion] martin-g commented on a diff in pull request #4360: Adding more dataframe example to read csv files

martin-g commented on code in PR #4360:
URL: https://github.com/apache/arrow-datafusion/pull/4360#discussion_r1032439566


##########
datafusion-examples/examples/dataframe.rs:
##########
@@ -41,3 +44,37 @@ async fn main() -> Result<()> {
 
     Ok(())
 }
+
+// Example to read data from a csv file with inferred schema
+async fn example_read_csv_file_with_inferred_schema() -> Arc<DataFrame> {
+    let path = "example.csv";
+    // Create the data to put into the csv file with headers
+    let content = "id,time,vote,unixtime,rating\na1,\"10 6, 2013\",3,1381017600,5.0\na2,\"08 9, 2013\",2,1376006400,4.5";
+    // write the data
+    fs::write(path, content).expect("Problem with writing file!");
+    // Create a session context and create a lazy

Review Comment:
   `... create a lazy ???`
   the sentence seems unfinished



##########
datafusion-examples/examples/dataframe.rs:
##########
@@ -41,3 +44,37 @@ async fn main() -> Result<()> {
 
     Ok(())
 }
+
+// Example to read data from a csv file with inferred schema
+async fn example_read_csv_file_with_inferred_schema() -> Arc<DataFrame> {
+    let path = "example.csv";
+    // Create the data to put into the csv file with headers
+    let content = "id,time,vote,unixtime,rating\na1,\"10 6, 2013\",3,1381017600,5.0\na2,\"08 9, 2013\",2,1376006400,4.5";

Review Comment:
   ```suggestion
       let content = r#"id,time,vote,unixtime,rating
       a1,\"10 6, 2013\",3,1381017600,5.0
       a2,\"08 9, 2013\",2,1376006400,4.5"#;
   ```



##########
datafusion-examples/examples/dataframe.rs:
##########
@@ -41,3 +44,37 @@ async fn main() -> Result<()> {
 
     Ok(())
 }
+
+// Example to read data from a csv file with inferred schema
+async fn example_read_csv_file_with_inferred_schema() -> Arc<DataFrame> {
+    let path = "example.csv";
+    // Create the data to put into the csv file with headers
+    let content = "id,time,vote,unixtime,rating\na1,\"10 6, 2013\",3,1381017600,5.0\na2,\"08 9, 2013\",2,1376006400,4.5";
+    // write the data
+    fs::write(path, content).expect("Problem with writing file!");
+    // Create a session context and create a lazy
+    let ctx = SessionContext::new();
+    let df = ctx.read_csv(path, CsvReadOptions::default()).await.unwrap();
+    df
+}
+
+// Example to read csv file with a given csv file
+async fn example_read_csv_file_with_schema() -> Arc<DataFrame> {
+    let path = "example.csv";
+    // Create the data to put into the csv file with headers
+    let content = "id,time,vote,unixtime,rating\na1,\"10 6, 2013\",3,1381017600,5.0\na2,\"08 9, 2013\",2,1376006400,4.5";

Review Comment:
   ```suggestion
       let content = r#"id,time,vote,unixtime,rating
       a1,\"10 6, 2013\",3,1381017600,5.0
       a2,\"08 9, 2013\",2,1376006400,4.5"#;
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org