[SPARK-56431][SQL] Fix NPE in FilterExec CSE when notNull columns are null before short-circuit#55288
Closed
LuciferYang wants to merge 1 commit intoapache:masterfrom
Closed
[SPARK-56431][SQL] Fix NPE in FilterExec CSE when notNull columns are null before short-circuit#55288LuciferYang wants to merge 1 commit intoapache:masterfrom
LuciferYang wants to merge 1 commit intoapache:masterfrom
Conversation
… null before short-circuit In `FilterExec.doConsume`, bind `otherPreds` against `child.output` (instead of `output`) for both CSE analysis and predicate code generation. SPARK-56032 added CSE support to FilterExec. The CSE precomputation runs before the IsNotNull predicates short-circuit. However, the bound expressions were using `output` (where notNullAttributes columns have nullable=false), causing the CSE-generated code to omit null checks. At runtime, when a row has a null value in such a column, the precomputation crashes with NPE (e.g. Decimal.subtract on null) before the IsNotNull check can filter the row out. Binding against `child.output` preserves the original nullability so the CSE-extracted code emits proper null guards.
dongjoon-hyun
approved these changes
Apr 10, 2026
Contributor
Author
|
Merged into master. Thanks @dongjoon-hyun |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
In
FilterExec.doConsume, bindotherPredsagainstchild.output(instead ofoutput) for both CSE analysis and predicate code generation.Why are the changes needed?
SPARK-56032 added CSE support to
FilterExec. The CSE precomputation code runs before theIsNotNullpredicates short-circuit, at the start of thedo {} while(false)block. However, theboundOtherPredspassed to CSE analysis were bound againstoutput, where columns innotNullAttributeshavenullable=false. This caused the CSE-generated code to omit null checks for those columns. At runtime, when a row has a null value in such a column, the precomputationcalls an arithmetic operator (e.g.
Decimal.subtract) on the null value before theIsNotNullcheck can filter the row out, resulting in an NPE.The original SPARK-56032 design comment states:
This assumption is only correct when the expressions preserve their input columns' original nullability. Binding against
output(with tightened nullability) breaks it.Reproducer: a
FilterExecover a source with a nullableDecimalTypecolumn, where the filter has bothIsNotNull(col)and a repeated arithmetic expression oncol(creating a CSE candidate), and at least one input row hascol = null.Does this PR introduce any user-facing change?
No. This optimization has not been released yet.
How was this patch tested?
Added a new test in
WholeStageCodegenSuite.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code