I have created one function using python in Databricks notebook
%python
import numpy as np
from pyspark.sql.functions import udf
# from pyspark.sql.types import DateType
def get_work_day(start_date,work_days_to_be_added,site_work_days,holidays_list):
holidays_list = list(holidays_list)
if (site_work_days == 5):
work_days = '1111100'
elif (site_work_days == 6):
work_days = '1111110'
elif (site_work_days == 7):
work_days = '1111111'
elif (site_work_days == 1):
work_days = '1000000'
elif (site_work_days == 2):
work_days = '1100000'
elif (site_work_days == 3):
work_days = '1110000'
elif (site_work_days == 4):
work_days = '1111000'
dt = np.busday_offset(start_date,work_days_to_be_added,roll='forward',weekmask = work_days,holidays=holidays_list)
return str(dt)
spark.udf.register("get_work_day()", get_work_day)
It works fine when I call it from the same notebook but throws an error when I call it from other notebooks.
I am calling the above function in SQL code and SQL code works fine when executing in the same notebooks but it breaks when I run it in other notebooks
Select column_with_date_value,get_work_day(column_with_date_value,4,4,('2021-05-06','2021-05-07')) from db.samp
The error I get is
DatabricksExceptions$SQLExecutionException: org.apache.spark.sql.AnalysisException: Undefined function: 'get_work_day'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 28
Can anyone please tell me on how to register this functions so that they can used accross notebooks.

