Skip to content

Commit 2f64af5

Browse files
committed
feat: add COPY TO parquet example with all tables + single udtf
1 parent 5326433 commit 2f64af5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

examples/parquet.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
 (0)