Repository navigation
[VL] Support Arrow-optimized Python UDTF offload (continues #12276) - #13731
Draft
dadarshabhat1 wants to merge 14 commits into
Draft
dadarshabhat1 wants to merge 14 commits into
dadarshabhat1 wants to merge 14 commits into
Conversation
- Move the Spark version specific code (PythonUDTF, ArrowEvalPythonUDTFExec and ArrowPythonUDTFRunner only exist since Spark 3.5 and differ in 4.0/4.1) into ArrowEvalPythonUDTFShim so the build passes on all Spark versions. - Join each Python output batch with its input row via HybridRowQueue, the same way as Spark does, so requiredChildOutput (e.g. LATERAL joins) and terminate() results are correct. - Use BatchIterator instead of grouped() which buffered mutable projected rows, and propagate job artifact UUID and Python metrics. - Provide a default no-op in SparkPlanExecApi so other backends are unaffected, gated by spark.gluten.sql.columnar.arrowUdf. - Add ArrowEvalPythonUDTFSuite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Run Gluten Clickhouse CI on x86 |
added 2 commits
November 23, 2026 22:43
Output ArrowJavaBatchType instead of VanillaBatchType, so Velox imports the UDTF output through OffloadArrowData and the Arrow C data interface rather than ColumnarToRow -> RowToVeloxColumnar. - Copy each Python batch once, with VectorAppender, into Gluten's Arrow allocator before the runner reuses its buffers, and coalesce results into batches of up to spark.gluten.sql.columnar.maxBatchSize rows. - Write each input row's required child columns once and repeat them by index for its output rows. - Check the Python output types with a local helper instead of Spark's equalsIgnoreCompatibleCollation, whose Seq overload is missing in Spark 4.0.0. - Fall back for spark.sql.execution.arrow.useLargeVarTypes and for user-defined types. - Move ArrowPythonUDTFEvaluator to shims/common. The shims now only build the runner input and return its raw output. - Only match SQL_ARROW_TABLE_UDF, since Spark 4.1+ also plans SQL_ARROW_UDTF through ArrowEvalPythonUDTFExec. - Add the Spark 4.2 shim.
|
Run Gluten Clickhouse CI on x86 |
|
Run Gluten Clickhouse CI on x86 |
|
Run Gluten Clickhouse CI on x86 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes are proposed in this pull request?
This continues #12276 by @FelixYBW. It offloads Spark's
ArrowEvalPythonUDTFExec(Arrow-optimized Python UDTFs,useArrow=True, Spark 3.5+) toColumnarArrowEvalPythonUDTFExecin the Velox backend. The original commits are kept unchanged with their authorship. The changes on top are in e9eaebe.Output goes to Velox as Arrow, not rows
ColumnarArrowEvalPythonUDTFExecnow outputsArrowJavaBatchTypeinstead ofVanillaBatchType. WithVanillaBatchType, a Velox parent gotColumnarToRow -> RowToVeloxColumnar. Now it getsOffloadArrowData -> ArrowColumnarToVeloxColumnar, which imports the buffers through the Arrow C data interface. This follows the approach described in the #12276 comment.VectorAppender, into Gluten's Arrow allocator before the runner reuses its buffers. The output memory is now tracked by Gluten.spark.gluten.sql.columnar.maxBatchSizerows.requiredChildOutputvalues are written once and repeated by index for its output rows.ColumnarArrowEvalPythonExecafter [GLUTEN-13706][VL] Fix pandas UDFs on partitions with more than one batch #13707.terminate()rows join the last input row, or a null row if the partition is empty.Fixes to #12276
NoSuchMethodError: the 4.0 shim calledDataType.equalsIgnoreCompatibleCollation(Seq[DataType], Seq[DataType]), which only exists since 4.0.1. The output type check now uses a local helper that ignores string collations.@arrow_udtf: Spark 4.1+ also plansSQL_ARROW_UDTF(302) throughArrowEvalPythonUDTFExec, and its worker doesn't return one batch per input row. The shims now only matchSQL_ARROW_TABLE_UDF(301).shims/spark42shim. Without it, Spark 4.2 didn't compile after mergingmain.Structure
ArrowPythonUDTFEvaluatoris now defined once, inshims/common. Each version's shim only builds the arguments forArrowPythonUDTFRunnerand returns its raw output. The 4.2 shim is the same as 4.1's. The two versions' signatures and the bytecode ofArrowEvalPythonUDTFExec/EvalPythonUDTFExecmatch.backends-velox.spark.sql.execution.arrow.useLargeVarTypes=trueand for user-defined types. Other unsupported types are rejected by Gluten's schema validation.BatchEvalPythonUDTFExec) and scalar Arrow UDFs are not affected.Still to do
HybridRowQueuespilling; named arguments andTABLE(...) PARTITION BYon 4.0; a plan check that noColumnarToRow/RowToVeloxColumnarpair is inserted above the UDTF; a join or aggregation consuming the output.main(where the UDTF falls back).How was this patch tested?
backends-velox(main and test code) compiles with-Pbackends-velox -Pjava-17for Spark 3.4, 3.5, 4.0, 4.1 and 4.2.ArrowEvalPythonUDTFSuitefrom [VL] support arrow UDTF #12276, and the tests listed under "Still to do". They need a Python environment withpyspark,pandasandpyarrow, which I'm setting up.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-opus-5-5). The original commits from #12276 were also generated with Claude Code, as stated in that PR.