I received the solution from Microsoft Support:
- Create Repos
- Add the Bar class in a separate python file test.py
from pydantic import BaseModel
class Bar(BaseModel):
a: int = 0
3.Create a new notebook in the repos and try importing the class from the python file which is already defined.
from pydantic import BaseModel
from pyspark.sql import functions as F
from pyspark.sql import Row
from pyspark.sql.types import StringType
from test import Bar
data = [
Row(zip_code='58542', dma='MIN'),
Row(zip_code='58701', dma='MIN'),
Row(zip_code='57632', dma='MIN')
]
df = spark.createDataFrame(data)
@F.udf(StringType())
def udf_test(dossier):
test = Bar()
return "test"
df.withColumn("test", udf_test(df['zip_code'])).show()