holdenk opened a new pull request, #60682:
URL: https://github.com/apache/spark/pull/60682
Backport-of: #59108
### What changes were proposed in this pull request?
Backport #59108 with release-branch follow-ups beyond the original master
commit
`dc73d212ae6`:
1. **NULL proofs.** Ordering comparisons omit their raising guard only when
both operands
are proven non-null; `len()` does so when its argument is proven
non-null. Proofs cover
if/ternary branches, reversed None
checks, `and`/`or` operands and arithmetic requiring both operands to be
non-null, and are
restored when leaving their scope.
2. **Early returns.** Normalize a two-statement `if <test>: return y`
followed by `return body`
only when the test proves a parameter non-null. Unsupported shapes keep
interpreted Python.
3. **Advisory.** Emit one named construction-time NULL-guard warning after
successful
transpilation, outside the fallback exception handler. Escalating it
cannot silently discard
successful options; a UDF with no lowered option gets no NULL-guard
advisory.
4. **Boolean len comparisons.** These now lower in BooleanType and
conditional contexts.
A len comparison declared with a numeric return type falls back to
interpreted Python.
5. **Repeat-count scope.** One shared admission rule in category inference
and conversion keeps
the previously numeric len-comparison counts, including all-len ternary
result branches and
supported None-identity comparisons. It restores both repeat operand
orders without admitting
ordinary comparison counts such as `s * (x > 0)`. A count with a None
result branch still falls
back.
6. **Later raising guards.** A len-comparison `and`/`or` chain falls back
when an operand after
the first still emits a len or ordering-comparison NULL guard. Fully
narrowed chains retain
native lowering; existing chains without len comparisons keep their
previous behavior.
The repeat/guard repairs and negative proof-site coverage are branch
follow-ups, not a claim that
all of this behavior was present in the original master cherry-pick.
### Why are the changes needed?
Removing guards justified by a None proof gives the null-guard idiom smaller
native plans.
Expanded len-comparison eligibility also needs bounded repeat admission and
later-guard safety:
Catalyst can share or factor a raising expression ahead of a Python
short-circuit. Unsupported
counts and chains keep the interpreted path instead of relying on that
evaluation order.
### Does this PR introduce _any_ user-facing change?
Yes. Proven non-null operations have leaner plans, successful lowerings
retaining NULL guards
emit a named advisory, and Boolean len comparisons become eligible in
additional contexts.
As with other lowered expressions, the transpiler's documented differences
from Python for NaN
ordering and unguarded arithmetic over NULL apply when a null-guard
early-return body is lowered.
The broader review question remains open: should newly admitted unguarded
Boolean len bodies
that inherit NaN ordering or NULL-arithmetic differences keep native
eligibility, or fall back to
Python? The bounded repeat, later-guard and proof-site repairs do not decide
that scope:
https://github.com/apache/spark/pull/59978#discussion_r4577202319
### How was this patch tested?
Unit tests cover native NULL proofs, reversed/compound branch proofs, proof
restoration,
all-len ternary and identity repeat counts, excluded ordinary comparison
counts, later ordering
fallback, false repeat counts, and warning filters. Negative cases assert
native plans retain
raise_error and raise the expected error; a separate early-return case
asserts Python fallback.
Positive repeat cases assert the JVM keeps the native option.
The exact candidate head `c736e207d895` passed `spark-presend --fast --base
branch-4.x` on system
Java 21 after a Hive-enabled rebuild/test compilation. Lint/license checks
passed. All five
selected test goals were green on the first run, with zero failures or
flakes:
- `pyspark.sql.tests.test_udf_transpile_unit`
- `pyspark.sql.tests.test_udf`
- `pyspark.sql.udf`
- `pyspark.sql.tests.test_udf_transpile_hypothesis`: all 23 tests passed with
`RUN_HYPOTHESIS=1` and `RUN_HYPOTHESIS_MAX_EXAMPLES=200`
- `pyspark.sql.tests.test_udf_transpile_parity`
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-6), November bounded repairs and proof-site tests.
Co-authored by: Claude Sonnet 4.6 (historical contribution).
Co-authored by: Kimi Code CLI (historical contribution).
Closes #59108 from jzhan-2026/spark-58628-non-nullable-null-guard.
Authored-by: jzhan-2026 <[email protected]>
Co-authored-by: [email protected] <[email protected]>
Signed-off-by: Holden Karau <[email protected]>
(cherry picked from commit dc73d212ae6213f0079ffd01dce7dad99e7db827)
Signed-off-by: Holden Karau <[email protected]>
Backport-PR: #59978
Co-authored-by: Holden Karau <[email protected]>
Signed-off-by: Holden Karau <[email protected]>
(cherry picked from commit 8a72d137331c9249a14e333953d5974bd22bddda)
Signed-off-by: Holden Karau <[email protected]>
--
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]