fix: codegen dispatcher returns NULL for invalid try_make_timestamp inputs (#4554)#4579
Open
andygrove wants to merge 2 commits into
Open
fix: codegen dispatcher returns NULL for invalid try_make_timestamp inputs (#4554)#4579andygrove wants to merge 2 commits into
andygrove wants to merge 2 commits into
Conversation
…roots (apache#4554) `MakeTimestamp(failOnError=false)` is `NullIntolerant=true` but its `doGenCode` catches `DateTimeException` for invalid year/month/day/hour/min/sec components and sets `ev.isNull = true`. The codegen dispatcher's NullIntolerant short- circuit conflated "null in -> null out" with "non-null in -> non-null out" and dropped the post-eval guard, so invalid rows received stale `ev.value` bytes instead of NULL. `try_make_timestamp` (which rewrites to MakeTimestamp with `failOnError=false`) and the non-ANSI MakeTimestamp path were both affected. Wrap the post-`ev.code` write in `if (ev.isNull) setNull else write` whenever the bound expression is nullable; non-nullable roots keep the direct write.
mbutrovich
approved these changes
Jun 3, 2026
Contributor
There was a problem hiding this comment.
Thanks for the fix, @andygrove! I really like seeing these types of fixes to codegen since I'm sure it fixes more than just this one expression that you tried.
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.
Which issue does this PR close?
Closes #4554.
Rationale for this change
try_make_timestamprewrites toMakeTimestamp(failOnError = false), which Spark'sdoGenCodeimplements with atry { ... } catch (DateTimeException e) { ev.isNull = true; }block. With Comet's codegen dispatcher routingMakeTimestampthrough Spark's own codegen, the kernel was honoring the input-null short-circuit but skipping the post-evalev.isNullguard, so invalid date/time components (month=13, day=32, hour=25, ...) returned staleev.valuebytes instead of NULL.The dispatcher's
defaultBodyconflatedNullIntolerant's "null in → null out" guarantee with the converse "non-null in → non-null out", whichMakeTimestamp(failOnError=false)does not satisfy. The same path also affects non-ANSImake_timestampdirectly, since that is the same expression with the same flag.What changes are included in this PR?
CometBatchKernelCodegen.defaultBody: in theNullIntolerant && allNullIntolerantbranch, when the bound expression is nullable, wrap the post-ev.codewrite inif (ev.isNull) setNull else write. Non-nullable roots keep the direct write (the existing optimization).CometCodegenSourceSuite: lock in the fix with a generated-source assertion thatMakeTimestamp(failOnError=false)emits twosetNullsites — input short-circuit + post-eval guard.make_timestamp.sql: add column and literal queries with invalid components covering month/day/hour/minute out-of-range. These ride the defaultfailOnError=falsepath (ANSI off inCometSqlFileTestSuite).try_make_timestamp.sql(new, Spark 4.0+): direct coverage fortry_make_timestampwith both column and literal invalid inputs, plus a sentinel valid query so the dispatcher must run natively.How are these changes tested?
CometCodegenSourceSuite(Spark 3.5): 51/51 pass; the new test fails on the unmodified codegen and passes with the fix.CometSqlFileTestSuitemake_timestampfilter (Spark 3.5 and 4.0): all three fixtures pass; on 3.5try_make_timestamp.sqlis skipped viaMinSparkVersion: 4.0.CometCodegenSuite,CometCodegenHOFSuite,CometTemporalExpressionSuite: pass.