[SPARK-57168][SQL] Simplify GetTimestamp codegen under ANSI mode#56218
Open
gengliangwang wants to merge 1 commit into
Open
[SPARK-57168][SQL] Simplify GetTimestamp codegen under ANSI mode#56218gengliangwang wants to merge 1 commit into
gengliangwang wants to merge 1 commit into
Conversation
### What changes were proposed in this pull request?
Add `DateTimeExpressionUtils.parseToTimestampExact(TimestampFormatter formatter,
String input, long downScaleFactor, boolean forTimestampNTZ, String
suggestedFuncOnFail)` and route the ANSI (`failOnError = true`) eval and codegen
paths of `ToTimestamp` (the base of `GetTimestamp` / `to_timestamp` etc.) through
it. The helper parses via `parseWithoutTimeZone` (TIMESTAMP_NTZ, no down-scaling)
or `parse` + `/ downScaleFactor`, and translates a `DateTimeException` (which
covers `DateTimeParseException`) or `ParseException` to `ansiDateTimeParseError`;
any other exception (e.g. `IllegalStateException`) propagates unchanged, matching
the previous behavior.
`ToTimestamp.doGenCode` previously emitted the same 5-line
`try { parse } catch (DateTimeException) catch (ParseException)` block at both
string call sites (the cached-formatter path and the per-row-formatter path). A
local `parseTimestampCode` now dispatches on `failOnError`: the ANSI branch emits
a single `parseToTimestampExact(...)` call; the non-ANSI branch keeps the inline
`try/catch -> isNull`. The eval path delegates to the same helper for consistency.
### Why are the changes needed?
Part of SPARK-56908 (umbrella). Collapsing the duplicated inline try/catch to a
single helper call shrinks the generated Java for the common `to_timestamp` /
`unix_timestamp` family.
### 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?
```
build/sbt "catalyst/testOnly *DateExpressionsSuite"
```
75/75 pass (exercised both with and without whole-stage codegen).
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)
Co-authored-by: Isaac
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?
Add
DateTimeExpressionUtils.parseToTimestampExact(TimestampFormatter formatter, String input, long downScaleFactor, boolean forTimestampNTZ, String suggestedFuncOnFail)and route the ANSI (failOnError = true) eval and codegen paths ofToTimestamp(the base ofGetTimestamp/to_timestamp,unix_timestamp, etc.) through it. The helper parses viaparseWithoutTimeZone(TIMESTAMP_NTZ, no down-scaling) orparse+/ downScaleFactor, and translates aDateTimeException(which also coversDateTimeParseException) or aParseExceptiontoansiDateTimeParseError; any other exception (e.g.IllegalStateException) propagates unchanged, matching the previous behavior.ToTimestamp.doGenCodepreviously emitted the same 5-linetry { parse } catch (DateTimeException) catch (ParseException)block at both string call sites (the cached-formatter path and the per-row-formatter path). A localparseTimestampCodenow dispatches onfailOnError: the ANSI branch emits a singleparseToTimestampExact(...)call, while the non-ANSI branch keeps the inlinetry/catch -> isNullform (the same shape used by the already-mergedMakeDate/MakeIntervalcleanups). The eval path delegates to the same helper for consistency.Why are the changes needed?
Part of SPARK-56908 (umbrella). Collapsing the duplicated inline try/catch to a single helper call shrinks the generated Java for the common
to_timestamp/unix_timestampfamily, 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?
75/75 pass (exercised both with and without whole-stage codegen).
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)