jischeng opened a new pull request, #60321:
URL: https://github.com/apache/spark/pull/60321
### What changes were proposed in this pull request?
This PR prunes child attributes that are only needed to evaluate `PythonUDF`
/ `PythonUDTF` inputs—and are not referenced by operators above
`EvalPython`—out of `BaseEvalPython`, `EvalPythonExec`, `EvalPythonUDTFExec`,
and `HybridRowQueue`:
1. **Logical Plan & Catalyst Optimizer (`BaseEvalPython`, `ColumnPruning`,
`SparkOptimizer`)**:
- Adds `requiredChildOutput: Seq[Attribute]` to `BaseEvalPython`
(`BatchEvalPython`, `ArrowEvalPython`), preserving source- and
binary-compatible `apply` factories defaulting to `child.output`.
- Teaches `ColumnPruning` to narrow `requiredChildOutput` under
`Project(_, e: BaseEvalPython)`, and runs `ColumnPruning` after
`ExtractPythonUDFs` / `ExtractPythonUDTFs` + `PushPredicateThroughNonJoin` in
`SparkOptimizer`.
2. **Physical Execution (`EvalPythonExec`, `EvalPythonUDTFExec`, and
Evaluator Factories)**:
- Buffers only `requiredChildOutput` in `HybridRowQueue` across
`EvalPythonEvaluatorFactory`, `ColumnarArrowEvalPythonEvaluatorFactory`
(calling `closeIfFreeable()` on pruned non-passthrough vectors),
`InProcessArrowEvalPythonEvaluatorFactory`, and `EvalPythonUDTFExec`.
- Skips `HybridRowQueue` allocation completely when
`requiredChildOutput.isEmpty`.
Closes #60320.
### Why are the changes needed?
When filtering or projecting with a Python/Pandas/Arrow UDF or UDTF over
wide columns (e.g., `SELECT id FROM t WHERE python_udf(large_blob)` or `SELECT
id, pandas_udf(large_blob) FROM t`), `EvalPythonExec` previously buffered all
of `child.output`—including `large_blob`—into `HybridRowQueue` while waiting on
the Python worker, wasting gigabytes of task execution memory and disk spill
I/O on columns that are immediately discarded above `EvalPythonExec`.
### Does this PR introduce _any_ user-facing change?
No behavior change; reduces task execution memory footprint, disk spill I/O,
and row projection overhead for Python UDF and Python UDTF queries.
### How was this patch tested?
- Added Catalyst and physical plan pruning tests in `ExtractPythonUDFsSuite`
(`BatchEvalPython`, `ArrowEvalPython`, pushed deterministic filters, empty
`requiredChildOutput`, and chained UDFs).
- Added `HybridRowQueue` field-count, row-size, and
empty-`requiredChildOutput` skip tests in `BatchEvalPythonExecSuite`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Google Antigravity
--
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]