cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Create persistent Scala UDF

amama
New Contributor II

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

feiyun0112
Honored Contributor

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

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now