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.

2 REPLIES 2

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

Kaniz_Fatma
Community Manager
Community Manager

Hey there! Thanks a bunch for being part of our awesome community! ๐ŸŽ‰ 

We love having you around and appreciate all your questions. Take a moment to check out the responses โ€“ you'll find some great info. Your input is valuable, so pick the best solution for you. And remember, if you ever need more help , we're here for you! 

Keep being awesome! ๐Ÿ˜Š๐Ÿš€

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group