How can I create a function like that https://docs.databricks.com/spark/latest/spark-sql/language-manual/create-function.html#create-function but defining the function in python?
I already did something like that:
from pyspark.sql.types import IntegerType
def relative_month(input_date):
if input_date is not None:
return ((input_date.month + 2) % 6)+1
else:
return None
_ = spark.udf.register("relative_month", relative_month, IntegerType())
But this UDF only works for the notebook that runs this piece of code.
I want to do the same thing using a SQL syntax to register the function because I will have some users using databricks trough SQL Clients and they will need the functions too.
In the Databricks docs says that i can define a resource:
: (JAR|FILE|ARCHIVE) file_uri
I need to create a .py file and put it somewhere in my databricks cluster?