Skip to content

[SPARK-57180][SQL] Skip statically-dead setNullAt branch in GenerateSafeProjection for non-nullable fields#56231

Open
gengliangwang wants to merge 1 commit into
apache:masterfrom
gengliangwang:spark-safeprojection-deadnull-codegen
Open

[SPARK-57180][SQL] Skip statically-dead setNullAt branch in GenerateSafeProjection for non-nullable fields#56231
gengliangwang wants to merge 1 commit into
apache:masterfrom
gengliangwang:spark-safeprojection-deadnull-codegen

Conversation

@gengliangwang
Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

GenerateSafeProjection emits if (isNull) { mutableRow.setNullAt(i); } else { convert; setColumn; } for every projected field. When the field expression is statically non-nullable, isNull is FalseLiteral, so the setNullAt branch is dead and only the else ever runs. This patch detects that case (evaluationCode.isNull == FalseLiteral -- the idiom already used by GenerateUnsafeProjection) and emits just the conversion + setColumn. The nullable path is unchanged. (GenerateMutableProjection already branches on e.nullable; this brings GenerateSafeProjection in line.)

Why are the changes needed?

Part of SPARK-56908 (umbrella). Removes a dead branch (and the setNullAt call) per non-nullable field from the generated safe projection, shrinking the emitted Java for wide non-nullable schemas (helping with the JVM 64KB method / constant-pool limits, Janino compile time, and JIT work).

Does this PR introduce any user-facing change?

No. The compiled behavior is identical; only the emitted Java source text changes.

How was this patch tested?

Added SPARK-57180: SafeProjection over statically non-nullable fields to GeneratedProjectionSuite, projecting non-nullable int/string/struct/array fields through an unsafe -> safe round trip and asserting the values.

build/sbt "catalyst/testOnly *GeneratedProjectionSuite"   # 10/10

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.8)

…afeProjection for non-nullable fields

### What changes were proposed in this pull request?

`GenerateSafeProjection` emits `if (isNull) { mutableRow.setNullAt(i); } else {
convert; setColumn; }` for every projected field. When the field expression is
statically non-nullable, `isNull` is `FalseLiteral`, so the `setNullAt` branch is
dead and only the `else` ever runs. This patch detects that case
(`evaluationCode.isNull == FalseLiteral`, the idiom already used by
`GenerateUnsafeProjection`) and emits just the conversion + `setColumn`. The
nullable path is unchanged. (`GenerateMutableProjection` already branches on
`e.nullable`; this brings `GenerateSafeProjection` in line.)

### Why are the changes needed?

Part of SPARK-56908 (umbrella). Removes a dead branch (and the `setNullAt` call)
per non-nullable field from the generated safe projection, shrinking the emitted
Java for wide non-nullable schemas.

### Does this PR introduce _any_ user-facing change?

No. The compiled behavior is identical; only the emitted Java source text changes.

### How was this patch tested?

Added `SPARK-57180: SafeProjection over statically non-nullable fields` to
`GeneratedProjectionSuite`, projecting non-nullable int/string/struct/array
fields through an unsafe -> safe round trip and asserting the values.

```
build/sbt "catalyst/testOnly *GeneratedProjectionSuite"   # 10/10
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.8)

Co-authored-by: Isaac
@gengliangwang gengliangwang requested a review from LuciferYang May 31, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant