You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "liningpan (via GitHub)" <gi...@apache.org> on 2026/07/16 20:54:20 UTC
[I] Optimize redundant calls to UDFs producing `StructArray` [datafusion]
liningpan opened a new issue, #23655:
URL: https://github.com/apache/datafusion/issues/23655
### 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 [https://github.com/liningpan/udf-get-field-optimization].
### 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_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Optimize redundant calls to UDFs producing `StructArray` [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew closed issue #23655: Optimize redundant calls to UDFs producing `StructArray`
URL: https://github.com/apache/datafusion/issues/23655
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Optimize redundant calls to UDFs producing `StructArray` [datafusion]
Posted by "tohuya6 (via GitHub)" <gi...@apache.org>.
tohuya6 commented on issue #23655:
URL: https://github.com/apache/datafusion/issues/23655#issuecomment-4998766963
take
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org