Skip to content

Commit 1bf775e

Browse files
authored
Support REST catalog views and SQL functions (#494)
1 parent 40500dc commit 1bf775e

22 files changed

Lines changed: 3182 additions & 41 deletions

bindings/python/src/context.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ impl PaimonCatalog {
7575
#[new]
7676
fn new(catalog_options: HashMap<String, String>) -> PyResult<Self> {
7777
let catalog = build_paimon_catalog(catalog_options)?;
78-
let provider = Arc::new(PaimonCatalogProvider::new(Arc::clone(&catalog)));
78+
let provider = Arc::new(PaimonCatalogProvider::new(
79+
None,
80+
Arc::clone(&catalog),
81+
Default::default(),
82+
Default::default(),
83+
None,
84+
));
7985
Ok(Self { catalog, provider })
8086
}
8187

crates/integrations/datafusion/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,30 @@
2424

2525
This crate contains the integration of [Apache DataFusion](https://datafusion.apache.org/) and [Apache Paimon](https://paimon.apache.org/).
2626

27+
## REST Catalog views and SQL functions
28+
29+
`SQLContext` can read persistent views and SQL scalar functions that already exist in a Paimon
30+
REST Catalog. No view or function DDL is added.
31+
32+
- A persistent view is resolved lazily like a table. The `datafusion` dialect is preferred and the
33+
default view query is used when that dialect is absent. Unqualified relations inside the view
34+
resolve in the view's owning catalog and database.
35+
- A SQL function can be called as `function(args...)` in the current catalog/database or as
36+
`catalog.database.function(args...)`. Its `definitions.datafusion` value must be a scalar SQL
37+
expression, it must be deterministic, and it must declare its input parameters and exactly one
38+
return parameter.
39+
- Only reads and execution are supported. Lambda/file functions, named arguments, multiple return
40+
values, non-deterministic functions, and calls made directly through a raw DataFusion
41+
`SessionContext` are not supported.
42+
43+
Use `SQLContext::sql` for function expansion:
44+
45+
```rust,ignore
46+
let mut ctx = paimon_datafusion::SQLContext::new();
47+
ctx.register_catalog("paimon", rest_catalog).await?;
48+
49+
let view = ctx.sql("SELECT * FROM analytics_view").await?;
50+
let function = ctx.sql("SELECT normalize_score(score) FROM scores").await?;
51+
```
52+
2753
See the [documentation](https://paimon.apache.org/docs/rust/datafusion/) for getting started guide and more details.

0 commit comments

Comments
 (0)