UDF importing from other modules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 07:16 AM
Hi community,
I am using a pyspark udf. The function is being imported from a repo (in the repos section) and registered as a UDF in a the notebook. I am getting a PythonException error when the transformation is run. This is comming from the databricks.sdk.runtime.__init__.py file with the import: from dbruntime import UserNamespaceInitializer. Then it's getting a ModuleNotFoundError: No module named dbruntime.
This udf uses functions imported from other module in the same repo (and third party modules). I'm wondering if there are limitations on doing this?
I can get the transformation to run if I put all of the code required, including the functions that are imported, into a notebook and run it but this is undesirable as we have a lot of supporting functions and really want to go down the traditional repo route. It's worth noting that non-udf imports from the repo do work (I've added it to the sys path), and also running the transform with a small dataset does work (so I assume it's a problem with the library availability on the workers).
Things I have tried that don't work:
- Importing dbruntime in the notebook.
- Registering all the modules used with spark.sparkContext.addPyFile("filepath") ... although I'm not sure if these would appear in the same namespace for importing in the python file.
- Using Runtime 13.3 and 14.3.
- Registering the udf in the file with the udf decorator.
- Importing dbruntime and databrick.sdk.runtime.* in the python files.
- Packaging the module into a wheel and installing it on the cluster (with and without registering this wheel with spark.sparkContext.addPyFile(<path-to-wheel>).
- Using the pyspark.pandas api with no udf registration (did this first as the tranformation function is written to be used in a pandas df.apply).
Any tips and advice would be much appreciated!
Tom