viirya opened a new pull request, #60277: URL: https://github.com/apache/spark/pull/60277
### What changes were proposed in this pull request? This PR backports #59551 (SPARK-60294) to branch-4.2. It disables `spark.sql.execution.arrow.pythonUDF.columnarInput.enabled` by default, and makes `ArrowEvalPythonExec.doExecute` check it too, through `supportsColumnar`, so that a child that also returns rows returns rows when columnar input is disabled. It also adds the `reuseVectors` and `batchSize` options to the test source `ArrowBackedDataSourceV2`. Differences from the original change, since branch-4.2 has no Arrow cache (`ArrowCachedBatchSerializer`): - `ArrowCachedPythonUDFSuite` and the change to `python/pyspark/sql/tests/arrow/test_arrow_python_udf_cached.py` are left out, as both test the Arrow cache. - The comment in `ArrowEvalPythonExec.doExecute` names an in-memory table scan instead of the scan of the Arrow cache as the example of a child that also returns rows. - The migration guide entry goes into the existing "Upgrading from Spark SQL 4.2.1 to 4.2.2" section, since 4.2.1 was released without this change, and does not mention the Arrow cache. The 4.3-to-4.4 entry is left out. ### Why are the changes needed? branch-4.2 still enables columnar input by default. With it enabled, the Arrow columnar path of `ColumnarArrowEvalPythonEvaluatorFactory` keeps the pass-through `ColumnVector`s of each input batch until the Python result of that batch comes back, which can be many batches later. A columnar reader may refill or release those vectors once it is asked for the next batch, so a scalar pandas or Arrow UDF on a column of such a source fails with `IndexOutOfBoundsException: index: 0, length: 1 (expected: range(0, 0))`, or pairs the pass-through values of a later batch with the UDF results of an earlier one. See #59551 for details. ### Does this PR introduce _any_ user-facing change? Yes. By default, Python UDFs on the columns of an Arrow-backed source no longer fail or return wrong results: Spark converts the batches to rows before the UDFs, as in Spark 4.1. Setting `spark.sql.execution.arrow.pythonUDF.columnarInput.enabled` to `true` enables columnar input again. The migration guide says so for 4.2.2. ### How was this patch tested? The new test of the original change in `ArrowColumnarPythonUDFSuite` passes on branch-4.2 with JDK 17, as do the other tests of the suite, `sql/scalastyle` and `sql/Test/scalastyle`. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5) This pull request and its description were written by Isaac. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
