Skip to content

Commit 3ec0216

Browse files
committed
fix: add example of register_tpch_udtfs
1 parent 443ada1 commit 3ec0216

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ using the [tpchgen](https://github.com/clflushopt/tpchgen-rs) crates.
1818
The `datafusion-tpch` crate offers two possible ways to register the TPCH individual
1919
table functions.
2020

21+
You can register functions individually.
22+
2123
```rust
2224
#[tokio::main]
2325
async fn main() -> Result<()> {
@@ -43,3 +45,25 @@ async fn main() -> Result<()> {
4345
}
4446
```
4547

48+
Or use the helper function `register_tpch_udtfs` to register all of them
49+
at once (which is the preferred approach).
50+
51+
```rust
52+
use datafusion_tpch::register_tpch_udtfs;
53+
54+
#[tokio::main]
55+
async fn main() -> Result<()> {
56+
// create local execution context
57+
let ctx = SessionContext::new();
58+
59+
// Register all the UDTFs.
60+
register_tpch_udtfs(&ctx);
61+
62+
// Generate the nation table with a scale factor of 1.
63+
let df = ctx
64+
.sql(format!("SELECT * FROM tpch_nation(1.0);").as_str())
65+
.await?;
66+
df.show().await?;
67+
Ok(())
68+
}
69+
```

0 commit comments

Comments
 (0)