dadarshabhat1 opened a new pull request, #13731:
URL: https://github.com/apache/gluten/pull/13731

   ## What changes are proposed in this pull request?
   
   This continues #12276 by @FelixYBW, which offloads Spark's 
`ArrowEvalPythonUDTFExec` (Arrow-optimized Python UDTF, Spark 3.5+) to a new 
`ColumnarArrowEvalPythonUDTFExec` in the Velox backend. The original commits 
are kept unchanged with their authorship, and the branch is merged with the 
latest `main`.
   
   It is a draft: this revision has the same code as #12276's head `ab3feaeaa` 
with no changes yet. The fixes below will follow in separate commits.
   
   ### Known issues to fix
   
   1. **Spark 4.2 doesn't compile.** `main` now has `shims/spark42`, and 
`OffloadSingleNodeRules` refers to `ArrowEvalPythonUDTFShim`, which doesn't 
exist there yet.
   2. **Spark 4.0.0 fails at runtime.** The 4.0 shim calls 
`DataType.equalsIgnoreCompatibleCollation(Seq[DataType], Seq[DataType])`, which 
was added in 4.0.1. Gluten builds against 4.0.2, so the shim compiles, but on 
4.0.0 it would fail with `NoSuchMethodError`. This will be replaced with a 
local helper.
   3. **Spark 4.1+ also matches `@arrow_udtf` (`SQL_ARROW_UDTF = 302`).** It's 
planned through the same `ArrowEvalPythonUDTFExec`, but doesn't return one 
batch per input row. The match will be limited to `SQL_ARROW_TABLE_UDF` (301).
   4. **Output converts back to rows.** The output is `VanillaBatchType`, so a 
Velox parent still gets `ColumnarToRow -> RowToVeloxColumnar`.
   
   ### Planned changes
   
   - **Shims:** limit the shims to building the arguments and calling 
`ArrowPythonUDTFRunner`, and return the runner's raw output. Move the shared 
evaluator trait to `shims/common` and add `spark42`.
   - **Exec output:** emit `ArrowJavaBatchType` in Gluten's Arrow allocator, so 
the batches go to Velox through `OffloadArrowData` without converting to rows. 
This follows the approach described in the [#12276 
comment](https://github.com/apache/gluten/pull/12276#issuecomment-5824667485).
   - **Batching:** write child columns once per input row, and coalesce the 
per-row Python batches into batches of about 
`spark.sql.execution.arrow.maxRecordsPerBatch` rows.
   - **Batch ownership:** each batch owns its buffers, following the pattern 
from #13707.
   - **Validation:** fall back for unsupported cases (eval type 302, 
`arrow.useLargeVarTypes`, UDT result types).
   - **Behaviour:** keep vanilla Spark's semantics for joining `terminate()` 
output to input rows.
   
   ## How was this patch tested?
   
   So far, only compile checks have been run on this branch, at the previous 
merge `1fd6ca8e2` with `-Pbackends-velox -Pjava-17`:
   - Spark 3.4, 3.5, 4.0 and 4.1 compile.
   - Spark 4.2 fails (issue 1).
   
   The new `ArrowEvalPythonUDTFSuite` from #12276 hasn't been run on this 
branch yet. More tests are planned: multiple and empty partitions, more data 
types, `HybridRowQueue` spilling, named arguments and `PARTITION BY` on 4.0, 
and plan-shape checks. Runs on Spark 3.5.4 and 4.0.0 are also planned.
   
   ## Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (claude-opus-5-5) for the analysis and merges in 
this revision. The original commits from #12276 were also generated with Claude 
Code, as stated in that PR.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to