RisingWave UDF materialization for dbt #22768
james-johnston-thumbtack
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Today, dbt doesn't offer support out-of-the-box for user-defined functions (UDFs) for any database engine. Many dbt users have asked for this support over the years and come up with various solutions. One of the more recent solutions was proposed by Paul Brabban on his blog: Materialized UDFs in a dbt World. Paul provided a prototype custom dbt materialization for BigQuery UDFs that accompanied this blog post.
A big advantage of using a custom dbt materialization for UDFs is that the UDF becomes part of your dbt DAG. You can use all the normal commands for building and running the UDF model to create it. It will be created in the proper order with other models that depend on the UDF. dbt node selectors can be used to optionally choose it when running, since it's part of the DAG. Overall, this seems to be a better solution than dbt run hooks.
Of course, the prototype was for BigQuery, not RisingWave. So I thought it would be useful to make a version of this UDF custom materialization for RisingWave. Here is what it looks like to use:
File
add_pair.sqlcreates a UDF namedadd_pair:If you then do
dbt run -s add_pair, it will create the RisingWave UDF. You could then reference it using therefkeyword, similar to the examples on Paul's blog, linked above.Now, interesting as this may be, I don't think this makes sense to make it an official part of RisingWave's dbt adapter, which is why I'm posting here and not as a pull request. The reason is that dbt is now planning to add out-of-the-box UDF support to dbt Core. It is part of the May 2025 roadmap post. Thus, in my opinion, it would be better for RisingWave to wait for official UDF support to be added to dbt, and then update the RisingWave dbt adapter to support it.
The preliminary specification shared by dbt is conceptually very similar to what Paul shared above: you'd put the body of the UDF in a dedicated
.sqlfile in your project somewhere, and define the UDF parameters in an accompanying YAML file. Then, you'd reference it usingreffrom other models, and it becomes part of your DAG.Anyway, until something official from dbt and RisingWave comes along, here's the custom materialization itself. The code is licensed under Apache 2.0, so feel free to use it.
Click to expand: macros/materializations/udf.sql
And here is the documentation for how to use it:
Click to expand: macros/materializations/udf.yml
Beta Was this translation helpful? Give feedback.
All reactions