[SPARK-57210][SQL] Skip statically-dead null-write branch in CreateNamedStruct codegen for non-nullable fields#56270
Conversation
…medStruct codegen for non-nullable fields CreateNamedStruct.doGenCode emitted an if (isNull) values[i]=null else values[i]=value block for every value child. For a non-nullable child the isNull branch is statically dead (eval.isNull is the constant false), so emit a single values[i]=value instead. Nullable children are unchanged. This mirrors GenArrayData.genCodeToCreateArrayData in the same file, which already gates the per-element null write on !expr.nullable (CreateArray/CreateMap already do this); CreateNamedStruct was the lone holdout. Shrinks the generated method per non-nullable field, scaling with struct width. Part of SPARK-56908.
dongjoon-hyun
left a comment
There was a problem hiding this comment.
+1, LGTM. Thank you, @LuciferYang .
|
Flagging against the scope guidance added to the umbrella SPARK-56908. This is a source-only dead-branch elimination: Janino constant-folds Before merging, please confirm this removes more than source text (a |
|
Close this PR after checking against the preceding criteria. thank you @gengliangwang @dongjoon-hyun |
What changes were proposed in this pull request?
CreateNamedStruct.doGenCodeemitted, for every value child, anif (isNull) values[i] = null; else values[i] = value;block. For a non-nullable child theisNullbranch is statically dead (eval.isNullis the constantfalse), so this skips it and emits a singlevalues[i] = value;. Nullable children are unchanged.This mirrors
GenArrayData.genCodeToCreateArrayDatain the same file, which already gates the per-element null write on!expr.nullable(soCreateArray/CreateMapalready do this) —CreateNamedStructwas the lone holdout.Why are the changes needed?
It removes a dead branch and the unreachable
values[i] = nullwrite per non-nullable field, shrinking the generated method. The win scales with struct width (e.g.struct(*)over a non-null schema), which helps with the JVM 64KB method / constant-pool limits, Janino compile time, and JIT work. Part of SPARK-56908.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing
ComplexTypeSuite(CreateStruct,CreateNamedStruct, SPARK-22693 codegen) andCodeGenerationSuitewide-struct tests already exercise both the non-nullable child (the new branch) and nullable children viacheckEvaluation, which runs the interpreted and codegen paths. Behavior is unchanged — the skipped write targets a slot thatnew Object[]already zero-initializes to null — so no new test is added, matching the in-file array (GenArrayData) convention.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.8)