19
19
20
20
# Example Usage
21
21
22
- Run a SQL query against data stored in a CSV:
22
+ ## Update ` Cargo.toml `
23
+
24
+ Add the following to your ` Cargo.toml ` file:
25
+
26
+ ``` toml
27
+ datafusion = " 7.0.0"
28
+ tokio = " 1.0"
29
+ ```
30
+
31
+ ## Run a SQL query against data stored in a CSV:
23
32
24
33
``` rust
25
34
use datafusion :: prelude :: * ;
@@ -28,18 +37,18 @@ use datafusion::prelude::*;
28
37
async fn main () -> datafusion :: error :: Result <()> {
29
38
// register the table
30
39
let mut ctx = ExecutionContext :: new ();
31
- ctx . register_csv (" example" , " tests/example.csv" , CsvReadOptions :: new ())? ;
40
+ ctx . register_csv (" example" , " tests/example.csv" , CsvReadOptions :: new ()). await ? ;
32
41
33
42
// create a plan to run a SQL query
34
- let df = ctx . sql (" SELECT a, MIN(b) FROM example GROUP BY a LIMIT 100" )? ;
43
+ let df = ctx . sql (" SELECT a, MIN(b) FROM example GROUP BY a LIMIT 100" ). await ? ;
35
44
36
45
// execute and print results
37
46
df . show (). await ? ;
38
47
Ok (())
39
48
}
40
49
```
41
50
42
- Use the DataFrame API to process data stored in a CSV:
51
+ ## Use the DataFrame API to process data stored in a CSV:
43
52
44
53
``` rust
45
54
use datafusion :: prelude :: * ;
@@ -48,7 +57,7 @@ use datafusion::prelude::*;
48
57
async fn main () -> datafusion :: error :: Result <()> {
49
58
// create the dataframe
50
59
let mut ctx = ExecutionContext :: new ();
51
- let df = ctx . read_csv (" tests/example.csv" , CsvReadOptions :: new ())? ;
60
+ let df = ctx . read_csv (" tests/example.csv" , CsvReadOptions :: new ()). await ? ;
52
61
53
62
let df = df . filter (col (" a" ). lt_eq (col (" b" )))?
54
63
. aggregate (vec! [col (" a" )], vec! [min (col (" b" ))])? ;
@@ -59,7 +68,7 @@ async fn main() -> datafusion::error::Result<()> {
59
68
}
60
69
```
61
70
62
- Both of these examples will produce
71
+ ## Output from both examples
63
72
64
73
``` text
65
74
+---+--------+
0 commit comments