dongjoon-hyun opened a new pull request, #60457: URL: https://github.com/apache/spark/pull/60457
### What changes were proposed in this pull request? This PR aims to avoid allocating a `WritableColumnVector[]` per row in `ColumnarArrowEvalPythonEvaluatorFactory.rowsToColumnarBatches`, as SPARK-61625 (#60444) did for `RowToColumnarExec`. When an Arrow Python UDF with columnar input passes some columns of its child through, `ColumnarArrowEvalPythonEvaluatorFactory` joins them with the Python results as rows, and `rowsToColumnarBatches` converts the joined rows back to `ColumnarBatch`es for a columnar parent, e.g., a stacked evaluation. It kept its column vectors as a `Seq` and called `converters.convert(row, vectors.toArray)`, so every row allocated a new array of the column count. This PR keeps the vectors as an `Array[WritableColumnVector]`, built once per partition, and passes it to `convert` directly. ```scala - val vectors = OnHeapColumnVector - .allocateColumns(initialCapacity, outputSchema).toSeq + val vectors: Array[WritableColumnVector] = OnHeapColumnVector + .allocateColumns(initialCapacity, outputSchema).toArray ... - converters.convert(row, vectors.toArray) + converters.convert(row, vectors) ``` `new ColumnarBatch(vectors.toArray)` still copies the array once per partition, as before. ### Why are the changes needed? The per-row array is pure overhead on the columnar output path of Arrow Python UDFs with `spark.sql.execution.arrow.pythonUDF.columnarInput.enabled=true` (default `false`). It has been there since SPARK-56350 (#55120) added that path in Apache Spark [v4.2.0](https://github.com/apache/spark/releases/tag/v4.2.0) (2026-07-11). The same idiom was pointed out during the review of #60444. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass the CIs with the existing tests. The following tests of `ArrowColumnarPythonUDFSuite` and `ArrowColumnarPythonUDFPipelinedSuite` reach `rowsToColumnarBatches`, which I confirmed by making it throw temporarily. - `SPARK-60325: The output batches of columnar input follow the limits of Arrow batches` - `SPARK-60325: Stacked Python UDFs over an Arrow-backed source` - `A row-based parent gets the joined rows of an evaluation with columnar input directly` ``` $ build/sbt 'sql/testOnly *ArrowColumnarPythonUDF* *ArrowCachedPythonUDFSuite' ... [info] Tests: succeeded 40, failed 0, canceled 0, ignored 0, pending 0 ``` ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 -- 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]
