Create persistent Scala UDF
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 08:34 AM
I've created a UDF in Scala (using Databricks notebook) which checks if the value of a field in a table is greater than 0, then sum those values. UDF is working as expected.
The problem is, that this UDF will be used by multiple SQLs across different notebooks. How can I make this UDF available to all the notebooks and avoid the re-creation of UDF in each notebook?
Thanks for the help.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 07:31 PM
In the child notebook:
def my_udf(x): return x + 1 spark.udf.register("my_udf", my_udf) dbutils.notebook.exit(my_udf)
In the master notebook:
child_udf = dbutils.notebook.run("PathToChildnotebook", timeout_seconds=600) spark.udf.register("my_udf", child_udf)
Solved: master notebook cannot find the udf registered in ... - Databricks - 6145

