apache / apache/datafusion

Optimize redundant calls to UDFs producing `StructArray`

クローズ
#23,655 コメント 1 件 リアクション 0 件 担当者 1 名 @tohuya6 が担当を希望しています GitHub で見る
enhancement
主要言語
Rust
スター
9.3k
フォーク
2.4k
平均マージ
3日 11時間
マージ済み PR(30日)
360

説明

### Is your feature request related to a problem or challenge?

Since UDF can only return a single column as output, returning a `StructArray` is desired in many cases. However, accessing fields of the returned struct results in redundant calls to the UDF.

```sql
SELECT
example_struct(c)['a'],
example_struct(c)['b']
FROM (SELECT unnest(range(1,100)) as c)
```

Datafusion produces the following projection step for the query, resulting in calling the UDF with the same column twice.

```
ProjectionExec: expr=[get_field(example_struct(c@0), a) as example_struct(c)[a], get_field(example_struct(c@0), b) as example_struct(c)[b]]
```

Note that calling the UDF in a CTE or view does not change the execution plan.

Here is a minimal example .

### Describe the solution you'd like

@adriangb mentioned that CSE (Common Sub-expression Elimination) optimizer might be able to handle this.

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

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

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

評価

この issue はまだ評価されていません。

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

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