apache / apache/datafusion-python

[Discussion] Define python UDF using `CREATE FUNCTION` SQL statement

オープン
#1,701 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Python
スター
604
フォーク
174
平均マージ
1日 7時間
マージ済み PR(30日)
4

説明

**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**

I would like to be able to define a python function using SQL `CREATE FUNCTION` statement.

Something like

```rust
let sql = r#"
CREATE FUNCTION to_miles(DOUBLE)
RETURNS DOUBLE
LANGUAGE PYARROW
AS '
import pyarrow.compute as pc

conversation_rate_multiplier = 0.62137119

def to_miles(km_data):
return pc.multiply(km_data, conversation_rate_multiplier)
'
"#;

ctx.sql(sql).await?.show().await?;

ctx.sql("select double_col, to_miles(double_col) from t")
.await?
.show()
.await?;
```

**Describe the solution you'd like**

datafusion provides pluggable `datafusion::execution::context::FunctionFactory` which could be wired to interpret python function definitions.

we could provide column based function definitions (`LANGUAGE PYARROW`) or row based (`LANGUAGE PYTHON`)

**Describe alternatives you've considered**

**Additional context**

- databricks has [similar functionality](https://docs.databricks.com/aws/en/udf/unity-catalog)

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start at datafusion::execution::context::FunctionFactory and trace how SQL CREATE FUNCTION definitions could be connected to Python UDF execution. Clarify whether column-based LANGUAGE PYARROW and row-based LANGUAGE PYTHON are in scope, then validate the CREATE FUNCTION and SELECT flow shown in the issue.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python, rust, sql
領域
databases
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
活発
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。