ivoson opened a new pull request, #59122: URL: https://github.com/apache/spark/pull/59122
### What changes were proposed in this pull request? **Problem** For non-Arrow Python UDFs, Spark evaluates the UDF input expressions and serializes the projected row using Java conversion followed by pickle serialization. A single row can contain a very large string or binary value. Because batching cannot split an individual row, converting and pickling it may create several large in-memory copies and cause an executor OOM before the row reaches the Python worker. Existing batch-size limits do not protect against this case. **Proposed change** Add an optional row-size guard for pickle-based Python UDFs. The guard should: - Run after UDF input expressions are projected, so computed values such as cast, concat, and substring are measured. - Run before Java conversion and pickle serialization. - Estimate the payload size of supported top-level variable-width arguments, initially strings and binary values. - Fail with a structured error when the estimated size exceeds a configurable threshold based on executor heap. - Introduce no per-row overhead when disabled or when the projected schema has no supported variable-width arguments. Pls note that: Nested arrays, maps, and structs are intentionally excluded initially to avoid a recursive traversal of every input value. ### Why are the changes needed? Avoid single giant row crashing executors. ### Does this PR introduce _any_ user-facing change? Yes. Previously, a single oversized input row for a pickle-serialized Python UDF was converted and serialized without a row-level size check, potentially causing executor OOM or a Python worker crash. This PR adds an opt-in guard that checks the combined payload size of top-level string and binary arguments after projection and before conversion and pickling. If the configured executor-heap fraction is exceeded, the query fails with UDF_LIMITS.ROW_SIZE. The guard is disabled by default, so default behavior remains unchanged. This capability is new relative to both released Spark versions and the current master branch. ### How was this patch tested? UTs ### Was this patch authored or co-authored using generative AI tooling? Generated-by: ClaudeCode Opus 4.8 -- 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]
