Skip to content

Commit 009039f

Browse files
authored
feat(datafusion): support REST Catalog CREATE FUNCTION (#499)
1 parent 4e67c89 commit 009039f

15 files changed

Lines changed: 1512 additions & 49 deletions

File tree

crates/integrations/datafusion/README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ This crate contains the integration of [Apache DataFusion](https://datafusion.ap
2626

2727
## REST Catalog views and SQL functions
2828

29-
`SQLContext` can read persistent views and SQL scalar functions in a Paimon REST Catalog. It can
30-
also create persistent REST Catalog views:
29+
`SQLContext` can read, execute, and create persistent views and SQL scalar functions in a Paimon
30+
REST Catalog:
3131

3232
```sql
3333
CREATE VIEW [IF NOT EXISTS] view_name [(column_name, ...)] AS query;
34+
35+
CREATE FUNCTION [IF NOT EXISTS] function_name([parameter_name data_type, ...])
36+
RETURNS data_type
37+
[LANGUAGE SQL]
38+
RETURN scalar_expression;
3439
```
3540

3641
- A persistent view is resolved lazily like a table. The `datafusion` dialect is preferred and the
@@ -44,10 +49,15 @@ CREATE VIEW [IF NOT EXISTS] view_name [(column_name, ...)] AS query;
4449
`catalog.database.function(args...)`. Its `definitions.datafusion` value must be a scalar SQL
4550
expression, it must be deterministic, and it must declare its input parameters and exactly one
4651
return parameter.
52+
- `CREATE FUNCTION` requires named parameters, one return type, and a scalar `RETURN` expression.
53+
`LANGUAGE SQL` is optional and SQL is the default, matching Databricks syntax. Determinism is
54+
inferred and validated from the planned expression before sending the REST create request. Bare,
55+
two-part, and three-part creation targets are supported; calls remain limited to bare and
56+
three-part names.
4757
- `CREATE OR REPLACE VIEW`, materialized/secure views, comments/options, persistent `ALTER VIEW` /
48-
`DROP VIEW`, and persistent function DDL are not supported. Lambda/file functions, named
49-
arguments, multiple return values, non-deterministic functions, and calls made directly through
50-
a raw DataFusion `SessionContext` are also not supported.
58+
`DROP VIEW`, `CREATE OR REPLACE/ALTER/TEMPORARY FUNCTION`, and persistent `ALTER FUNCTION` /
59+
`DROP FUNCTION` are not supported. Lambda/file, aggregate/table/multi-return, non-deterministic,
60+
Stable/Volatile, and non-SQL functions are also not supported.
5161

5262
Use `SQLContext::sql` for function expansion:
5363

@@ -56,8 +66,9 @@ let mut ctx = paimon_datafusion::SQLContext::new();
5666
ctx.register_catalog("paimon", rest_catalog).await?;
5767
5868
ctx.sql("CREATE VIEW daily_scores AS SELECT normalize_score(score) AS score FROM scores").await?;
69+
ctx.sql("CREATE FUNCTION plus_one(x BIGINT) RETURNS BIGINT RETURN x + 1").await?;
5970
let view = ctx.sql("SELECT * FROM analytics_view").await?;
60-
let function = ctx.sql("SELECT normalize_score(score) FROM scores").await?;
71+
let function = ctx.sql("SELECT plus_one(score) FROM scores").await?;
6172
```
6273

6374
See the [documentation](https://paimon.apache.org/docs/rust/datafusion/) for getting started guide and more details.

0 commit comments

Comments
 (0)