jischeng opened a new issue, #60320:
URL: https://github.com/apache/spark/issues/60320

   ### Describe the bug / improvement
   
   Currently, `BaseEvalPython` (`BatchEvalPython`, `ArrowEvalPython`) and 
`PythonUDTF` (`EvalPythonUDTFExec`) always append their UDF/UDTF results to the 
full `child.output`:
   
   ```scala
   override def output: Seq[Attribute] = child.output ++ resultAttrs
   ```
   
   When a child column is only needed as an input to a Python/Pandas/Arrow UDF 
or UDTF and is not referenced by operators above `EvalPython` (for example, 
`SELECT id FROM t WHERE python_udf(large_payload)` or `SELECT id, 
pandas_udf(large_payload) FROM t`), `EvalPythonExec` and `EvalPythonUDTFExec` 
still:
   1. Convert and buffer the unreferenced `large_payload` column into 
`HybridRowQueue` for every row while waiting on the Python worker, wasting 
gigabytes of task execution memory and disk spill I/O on wide 
string/binary/nested columns;
   2. Materialize and project those unreferenced pass-through columns out of 
`EvalPythonExec` only for the parent `Project` to immediately drop them.
   
   ### Proposed Solution
   
   1. Add `requiredChildOutput: Seq[Attribute]` to `BaseEvalPython` 
(`BatchEvalPython`, `ArrowEvalPython`) and `EvalPythonExec` / 
`EvalPythonUDTFExec` (keeping source/binary-compatible `apply` constructors 
defaulting to `child.output`).
   2. Teach Catalyst `ColumnPruning` to narrow `requiredChildOutput` under 
`Project(_, e: BaseEvalPython)`, and run `ColumnPruning` after 
`ExtractPythonUDFs` / `ExtractPythonUDTFs` + `PushPredicateThroughNonJoin` in 
`SparkOptimizer`.
   3. Buffer only `requiredChildOutput` in `HybridRowQueue` across 
`EvalPythonEvaluatorFactory`, `ColumnarArrowEvalPythonEvaluatorFactory` 
(releasing pruned Arrow column vectors via `closeIfFreeable()`), 
`InProcessArrowEvalPythonEvaluatorFactory`, and `EvalPythonUDTFExec`, skipping 
`HybridRowQueue` creation entirely when `requiredChildOutput.isEmpty`.


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