[Feature] Trino UDF Inline support
- Dominant language
- Rust
- Stars
- 13.8k
- Forks
- 2.6k
- Avg merge
- 21h 31m
- Merged PRs (30d)
- 56
Description
### Is this your first time submitting a feature request?
- [x] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [x] I have searched the existing issues, and I could not find an existing issue for this feature
- [x] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion
### Which version of dbt is this feature for?
dbt v2.x (Core or Fusion)
### Describe the feature
Add an opt-in Trino inline UDF compilation mode for dbt function resources.
Trino can store UDFs only in catalogs that support routine storage. Some projects cannot or do not want to persist UDF definitions in a Trino catalog, and instead need to use Trino inline UDFs with `WITH FUNCTION`.
Today, using inline UDFs in dbt requires each model to manually include the Trino `WITH FUNCTION ...` declaration for every UDF it calls. This adds boilerplate, duplicates UDF definitions across models, and makes UDF usage feel different from a normal SQL function call.
I would like dbt to support a Trino profile option, for example `inline_udfs: true`, that compiles referenced dbt `function` resources into Trino inline UDF declarations automatically.
The intended user experience is:
```sql
{{ config(inline_udfs=["score_label"]) }}
select score_label(score) as label
```
or:
```sql
select {{ function("score_label") }}(score) as label
```
With inline UDF mode enabled, dbt would compile the required WITH FUNCTION score_label(...) ... declaration into the model SQL automatically, so users can call the UDF like a normal function while dbt handles the Trino-specific inline boilerplate.
This should use explicit dbt function dependencies, not arbitrary macro detection, because macros can generate dynamic SQL and are not a reliable signal that a Trino UDF is being called.
### Describe alternatives you've considered
_No response_
### Who will this benefit?
This benefits dbt users running on Trino who want to use reusable UDF logic without persisting UDF definitions into a Trino catalog.
Concrete examples:
- Teams using Trino catalogs that do not support routine/UDF storage.
- Teams that are not allowed to create persistent UDFs because of governance, permissions, or platform ownership boundaries.
- Projects that want UDF behavior scoped to a single query/model instead of globally registered catalog objects.
- Analytics teams that want to define reusable dbt `function` resources, but still call them in model SQL like normal functions.
- Multi-environment dbt projects where storing UDFs in every dev/staging/prod catalog adds deployment overhead.
Example use case:
A project has a reusable scoring function:
```sql
score_label(score)
```
The function maps numeric scores into labels such as gold, silver, and bronze. Multiple models need to call this logic, but the team does not want to create a persistent Trino UDF in the catalog.
With this feature, the team can define the function once as a dbt function resource and write model SQL like:
```sql
{{ config(inline_udfs=["score_label"]) }}
select
customer_id,
score_label(score) as score_tier
from customers
```
dbt would compile the required Trino inline WITH FUNCTION declaration automatically. This keeps model SQL clean and avoids requiring catalog-stored UDF deployment.
### Are you interested in contributing this feature?
Yes - https://github.com/dbt-labs/dbt-core/pull/15345
### Anything else?
PR Opened - https://github.com/dbt-labs/dbt-core/pull/15345
Contributor guide
Assessment
This issue has not been assessed yet.