I'm trying to utilise the option to create UDFs in Unity Catalog. That would be a great way to have functions available in a fairly straightforward manner without e.g. putting the function definitions in an extra notebook that I %run to make them available.
So when I try to follow https://learn.microsoft.com/en-us/azure/databricks/udf/unity-catalog I create the following function:
CREATE OR REPLACE FUNCTION catalog.schema.WatermarkRead_UC(ADLSLocation STRING)
RETURNS STRING
LANGUAGE PYTHON
AS $$
WatermarkValue = spark.sql(f"SELECT WatermarkValue FROM PARQUET.`{ADLSLocation}/_watermark_log`").collect()[0][0]
return WatermarkValue
$$
And then call it:
SELECT catalog.schema.WatermarkRead_UC('abfss://container@storage.dfs.core.windows.net/path')
It returns the following error message:
NameError: name 'spark' is not defined
I tried all sorts of things but I couldn't make it work. Wouldn't spark be supported out of the box? The same function works as expected when I simply define it in a separate notebook, then %run that notebook and I can easily use the function and it runs and returns a value.
I wonder if it is a current limitation or a bug or an error in my code / design? Any help would be appreciated. Thanks
P.s.: I know I can register a UDF outside Unity Catalog and that I can create a Python wheel to import from in the notebooks but I'm after a UC-based solution if that is possible. Thanks