Skip to content

[SPARK-56915][SQL] Simplify MakeDate/MakeInterval codegen under ANSI mode#55940

Open
gengliangwang wants to merge 1 commit into
apache:masterfrom
gengliangwang:SPARK-56915-make-date-interval
Open

[SPARK-56915][SQL] Simplify MakeDate/MakeInterval codegen under ANSI mode#55940
gengliangwang wants to merge 1 commit into
apache:masterfrom
gengliangwang:SPARK-56915-make-date-interval

Conversation

@gengliangwang
Copy link
Copy Markdown
Member

Title: [SPARK-56915][SQL] Refactor MakeDate/MakeInterval codegen under ANSI mode
Base: master (independent)
Head: gengliangwang:SPARK-56915-make-date-interval

What changes were proposed in this pull request?

Introduce DateTimeConstructorUtils.java with two static helpers:

  • makeDateExact(int year, int month, int day): wraps LocalDate.of(...) + DateTimeUtils.localDateToDays(...) in the ansiDateTimeArgumentOutOfRange(DateTimeException) try/catch.
  • makeIntervalExact(int years, int months, int weeks, int days, int hours, int mins, Decimal secs): wraps IntervalUtils.makeInterval in the arithmeticOverflowError(message, "", null) try/catch.

datetimeExpressions.MakeDate and intervalExpressions.MakeInterval delegate to the helpers in their failOnError = true codegen + eval paths. The non-ANSI branch keeps the inline try/catch -> null form because it sets isNull = true on failure.

Why are the changes needed?

Part of SPARK-56908 (umbrella). The 7-line try/catch wrapper that maps DateTimeException / ArithmeticException to the user-facing ANSI error was emitted inline in doGenCode; the helper collapses it to a single call per call site without losing the wrapped exception's message (no QueryContext argument is involved, so this PR introduces no per-row references[] regression).

Does this PR introduce any user-facing change?

No.

How was this patch tested?

build/sbt "catalyst/testOnly *DateExpressionsSuite *IntervalExpressionsSuite"

96/96 pass.

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

Generated-by: Cursor 1.x

…mode

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

Introduce `DateTimeConstructorUtils.java` with two static helpers:
* `makeDateExact(int year, int month, int day)`: wraps
  `LocalDate.of(...) + DateTimeUtils.localDateToDays(...)` in the
  `ansiDateTimeArgumentOutOfRange(DateTimeException)` try/catch.
* `makeIntervalExact(int years, int months, int weeks, int days,
  int hours, int mins, Decimal secs)`: wraps `IntervalUtils.makeInterval`
  in the `arithmeticOverflowError(message, "", null)` try/catch.

`datetimeExpressions.MakeDate` and `intervalExpressions.MakeInterval`
delegate to the helpers in their `failOnError = true` codegen + eval
paths. The non-ANSI branch keeps the inline `try/catch -> null` form
because it sets `isNull = true` on failure.

### Why are the changes needed?

Part of SPARK-56908 (umbrella). The 7-line try/catch wrapper that maps
`DateTimeException` / `ArithmeticException` to the user-facing ANSI
error was emitted inline in `doGenCode`; the helper collapses it to a
single call per call site without losing the wrapped exception's
message (no `QueryContext` argument is involved, so this PR introduces
no per-row `references[]` regression).

### 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 *IntervalExpressionsSuite"
```

96/96 pass.

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

Generated-by: Cursor 1.x
@gengliangwang
Copy link
Copy Markdown
Member Author


Stack overview (SPARK-56908 umbrella)

This PR is part of a stack of 8 PRs against SPARK-56908. Order:

  1. [SPARK-56909][SQL] Simplify Cast to int/long codegen under ANSI mode #55934 — [SPARK-56909][SQL] Simplify Cast to int/long codegen under ANSI mode (this stack base)
  2. [SPARK-56910][SQL] Simplify Cast to byte/short codegen under ANSI mode #55935 — [SPARK-56910][SQL] Simplify Cast to byte/short codegen under ANSI mode
  3. [SPARK-56911][SQL] Simplify Cast to decimal codegen under ANSI mode #55936 — [SPARK-56911][SQL] Simplify Cast to decimal codegen under ANSI mode
  4. [SPARK-56912][SQL] Simplify Cast to boolean codegen under ANSI mode #55937 — [SPARK-56912][SQL] Simplify Cast to boolean codegen under ANSI mode
  5. [SPARK-56914][SQL] Simplify decimal arithmetic codegen under ANSI mode #55939 — [SPARK-56914][SQL] Simplify decimal arithmetic codegen under ANSI mode (depends on [SPARK-56911][SQL] Simplify Cast to decimal codegen under ANSI mode #55936)
  6. [SPARK-56913][SQL] Simplify BinaryArithmetic byte/short codegen under ANSI mode #55938 — [SPARK-56913][SQL] Simplify BinaryArithmetic byte/short codegen under ANSI mode (independent)
  7. [SPARK-56915][SQL] Simplify MakeDate/MakeInterval codegen under ANSI mode #55940 — [SPARK-56915][SQL] Simplify MakeDate/MakeInterval codegen under ANSI mode (independent)
  8. [SPARK-56916][SQL] Simplify ElementAt array codegen under ANSI mode #55941 — [SPARK-56916][SQL] Simplify ElementAt array codegen under ANSI mode (independent)

PRs 1-4 are linearly stacked on each other (each branch is based on the previous one). PR 5 (decimal arithmetic) is stacked on top of PR 3 (cast decimal) since it uses CastUtils.changePrecisionExact. PRs 6, 7, 8 branch off master independently.

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