File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ //! Example of using the datafusion-tpch extension to generate TPCH tables
2+ //! and writing them to disk via `COPY`.
3+
4+ use datafusion:: prelude:: { SessionConfig , SessionContext } ;
5+ use datafusion_tpch:: { register_tpch_udtf, register_tpch_udtfs} ;
6+
7+ #[ tokio:: main]
8+ async fn main ( ) -> datafusion:: error:: Result < ( ) > {
9+ let ctx = SessionContext :: new_with_config ( SessionConfig :: new ( ) . with_information_schema ( true ) ) ;
10+ register_tpch_udtf ( & ctx) ;
11+
12+ let sql_df = ctx. sql ( & format ! ( "SELECT * FROM tpch(1.0);" ) ) . await ?;
13+ sql_df. show ( ) . await ?;
14+
15+ let sql_df = ctx. sql ( & format ! ( "SHOW TABLES;" ) ) . await ?;
16+ sql_df. show ( ) . await ?;
17+
18+ let sql_df = ctx
19+ . sql ( & format ! (
20+ "COPY nation TO './tpch_nation.parquet' STORED AS PARQUET"
21+ ) )
22+ . await ?;
23+ sql_df. show ( ) . await ?;
24+
25+ register_tpch_udtfs ( & ctx) ?;
26+
27+ let sql_df = ctx
28+ . sql ( & format ! (
29+ "COPY (SELECT * FROM tpch_lineitem(1.0)) TO './tpch_lineitem_sf_10.parquet' STORED AS PARQUET"
30+ ) )
31+ . await ?;
32+ sql_df. show ( ) . await ?;
33+
34+ Ok ( ( ) )
35+ }
You can’t perform that action at this time.
0 commit comments