create local execution context with `cars.csv` registered as a table named `cars`
()
| 31 | |
| 32 | // create local execution context with `cars.csv` registered as a table named `cars` |
| 33 | async fn create_context() -> Result<SessionContext> { |
| 34 | // declare a new context. In spark API, this corresponds to a new spark SQL session |
| 35 | let ctx = SessionContext::new(); |
| 36 | |
| 37 | // content from file 'datafusion/core/tests/data/cars.csv' |
| 38 | let csv_data = r#"car,speed,time |
| 39 | red,20.0,1996-04-12T12:05:03.000000000 |
| 40 | red,20.3,1996-04-12T12:05:04.000000000 |
| 41 | red,21.4,1996-04-12T12:05:05.000000000 |
| 42 | red,21.5,1996-04-12T12:05:06.000000000 |
| 43 | red,19.0,1996-04-12T12:05:07.000000000 |
| 44 | red,18.0,1996-04-12T12:05:08.000000000 |
| 45 | red,17.0,1996-04-12T12:05:09.000000000 |
| 46 | red,7.0,1996-04-12T12:05:10.000000000 |
| 47 | red,7.1,1996-04-12T12:05:11.000000000 |
| 48 | red,7.2,1996-04-12T12:05:12.000000000 |
| 49 | red,3.0,1996-04-12T12:05:13.000000000 |
| 50 | red,1.0,1996-04-12T12:05:14.000000000 |
| 51 | red,0.0,1996-04-12T12:05:15.000000000 |
| 52 | green,10.0,1996-04-12T12:05:03.000000000 |
| 53 | green,10.3,1996-04-12T12:05:04.000000000 |
| 54 | green,10.4,1996-04-12T12:05:05.000000000 |
| 55 | green,10.5,1996-04-12T12:05:06.000000000 |
| 56 | green,11.0,1996-04-12T12:05:07.000000000 |
| 57 | green,12.0,1996-04-12T12:05:08.000000000 |
| 58 | green,14.0,1996-04-12T12:05:09.000000000 |
| 59 | green,15.0,1996-04-12T12:05:10.000000000 |
| 60 | green,15.1,1996-04-12T12:05:11.000000000 |
| 61 | green,15.2,1996-04-12T12:05:12.000000000 |
| 62 | green,8.0,1996-04-12T12:05:13.000000000 |
| 63 | green,2.0,1996-04-12T12:05:14.000000000 |
| 64 | "#; |
| 65 | let dir = tempdir()?; |
| 66 | let file_path = dir.path().join("cars.csv"); |
| 67 | { |
| 68 | let mut file = File::create(&file_path)?; |
| 69 | // write CSV data |
| 70 | file.write_all(csv_data.as_bytes())?; |
| 71 | } // scope closes the file |
| 72 | let file_path = file_path.to_str().unwrap(); |
| 73 | |
| 74 | ctx.register_csv("cars", file_path, CsvReadOptions::new()) |
| 75 | .await?; |
| 76 | |
| 77 | Ok(ctx) |
| 78 | } |
| 79 | |
| 80 | /// In this example we will declare a user defined window function that computes a moving average and then run it using SQL |
| 81 | pub async fn simple_udwf() -> Result<()> { |
no test coverage detected
searching dependent graphs…