Shivadarshan created SPARK-62320:
------------------------------------
Summary: Arrow Python UDTF with a NOT NULL output column fails
with "different schema" under the legacy pandas conversion when eval yields no
rows for some input rows
Key: SPARK-62320
URL: https://issues.apache.org/jira/browse/SPARK-62320
Project: Spark
Issue Type: Bug
Components: PySpark
Affects Versions: 4.3.0, 5.0.0
Reporter: Shivadarshan
With `useArrow=True` and the legacy pandas conversion, a Python UDTF that
declares a `NOT NULL` output column fails when its `eval` yields no rows for
some input rows and yields rows for others. It works when `eval` yields a row
for every input row, and without the legacy conversion.
```python
from pyspark.sql.functions import udtf
@udtf(returnType="a: int NOT NULL", useArrow=True)
class NotNullUDTF:
def eval(self, i: int):
for n in range(i):
yield (n,)
spark.udtf.register("notNullUDTF", NotNullUDTF)
spark.conf.set("spark.sql.legacy.execution.pythonUDTF.pandas.conversion.enabled",
"true")
spark.sql("SELECT * FROM range(0, 3, 1, 1) JOIN LATERAL
notNullUDTF(id)").collect()
```
This fails with:
```
Tried to write record batch with different schema
```
It should return `(1, 0), (2, 0), (2, 1)`. The same query works with the conf
set to `false`, and in the pickled (non-Arrow) mode. It also works in Spark
4.1.1 with the conf set to `true`, so this is a regression after 4.1.1. It
fails on 4.3.0 and on master.
This was found while working on SPARK-60564
(https://github.com/apache/spark/pull/60450), whose
`test_udtf_with_left_lateral_join_not_null_column` is skipped in the legacy
pandas conversion because of it. It is not related to that change: the inner
lateral join above fails on 4.3.0 too, without it.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]