There are different kinds of pandasUDFType depending upon the input and the output type of the function.
There is:
series to series PandasUDFType.SCALAR:
from pyspark.sql.functions import pandas_udf, PandasUDFType
@pandas_udf('long', PandasUDFType.SCALAR)
def pandas_plus_one(v):
return v + 1
spark.range(10).select(pandas_plus_one("id")).show()
And there is also Iterator of Series to Iterator of Series PandasUDFType.SCALAR_ITER:
from pyspark.sql.functions import pandas_udf, PandasUDFType
@pandas_udf('long', PandasUDFType.SCALAR_ITER)
def pandas_plus_one(iterator):
return map(lambda s: s + 1, iterator)
spark.range(10).select(pandas_plus_one("id")).show()
Can you please give me a simple usecase that cannot be solved by series to series PandasUDFType.SCALAR and can be solved by Iterator of Series to Iterator of Series PandasUDFType.SCALAR_ITER. I cannot seem to understand what is the need to have one while the other is still there