What exactly happens when I define a local variable, such as a huge list of complex objects, and use it inside an UDF in pyspark. Let me use this as an example:
huge_list = [<object_1>, <object_2>, ..., <object_n>]
@udf
def some_function(a, b):
l = []
for obj in huge_list:
l.append(a.operation(obj))
return l
df2 = df.withColumn('foo', some_function(col('a'), col('b')))
Is it broadcasted automatically? Or the nodes communicate with the master to get its data every time? What are the perfomance penalties that I have with this approach? Is there a better one? (Considering that it would be worse to build huge_list from scratch every time the UDF is applied)