Skip to content

[SPARK-49642][SQL] Remove the ANSI config suggestion in DATETIME_FIELD_OUT_OF_BOUNDS#54695

Closed
deepujain wants to merge 1 commit into
apache:masterfrom
deepujain:SPARK-49642-remove-ansi-suggestion-datetime-out-of-bounds
Closed

[SPARK-49642][SQL] Remove the ANSI config suggestion in DATETIME_FIELD_OUT_OF_BOUNDS#54695
deepujain wants to merge 1 commit into
apache:masterfrom
deepujain:SPARK-49642-remove-ansi-suggestion-datetime-out-of-bounds

Conversation

@deepujain

@deepujain deepujain commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Summary

In Spark 4.0.0 ANSI mode is on by default. The JIRA asks to minimize suggestions that tell users to turn ANSI off. The error DATETIME_FIELD_OUT_OF_BOUNDS previously had a subclass WITH_SUGGESTION that appended "If necessary set spark.sql.ansi.enabled to false to bypass this error." This PR removes that suggestion; users can use try_* functions for safe behavior instead. The error now always uses WITHOUT_SUGGESTION (message is just the range description).

Change

  • error-conditions.json: Removed the WITH_SUGGESTION subclass from DATETIME_FIELD_OUT_OF_BOUNDS (kept only WITHOUT_SUGGESTION).
  • QueryExecutionErrors.scala: ansiDateTimeArgumentOutOfRange now throws DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION with only rangeMessage (removed ansiConfig parameter).
  • SQL test result files (date.sql.out, timestamp.sql.out, timestampNTZ/timestamp-ansi.sql.out, postgreSQL/date.sql.out, datetime-legacy.sql.out): Updated expected error class from WITH_SUGGESTION to WITHOUT_SUGGESTION and removed ansiConfig from expected messageParameters where the error is DATETIME_FIELD_OUT_OF_BOUNDS.
  • QueryExecutionAnsiErrorsSuite.scala: Added a regression test for DATETIME_FIELD_OUT_OF_BOUNDS so the error does not suggest disabling ANSI mode.

Tests

Added SPARK-49642: DATETIME_FIELD_OUT_OF_BOUNDS does not suggest ANSI config in QueryExecutionAnsiErrorsSuite.

Local validation:

  • ./build/sbt "sql/testOnly org.apache.spark.sql.errors.QueryExecutionAnsiErrorsSuite -- -z SPARK-49642" passed.
  • ./build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z time.sql" passed.

Fixes SPARK-49642

JIRA assignee for credit: deepujain

@deepujain deepujain force-pushed the SPARK-49642-remove-ansi-suggestion-datetime-out-of-bounds branch 2 times, most recently from 96c0ccb to c298038 Compare March 12, 2026 04:44
@deepujain

Copy link
Copy Markdown
Contributor Author

Rebased on master. Local run: SQLQueryTestSuite for date/timestamp/datetime-legacy/timestamp-ansi (18 tests) and QueryExecutionAnsiErrorsSuite::SPARK-49642 (1 test)—all passed.

@deepujain deepujain force-pushed the SPARK-49642-remove-ansi-suggestion-datetime-out-of-bounds branch from c298038 to 8b93645 Compare March 15, 2026 15:15
@deepujain

Copy link
Copy Markdown
Contributor Author

Branch is rebased on master and local SQL/ANSI tests passed. No further changes from my side, ready for review when someone has bandwidth.

./build/sbt "sql/testOnly org.apache.spark.sql.errors.QueryExecutionAnsiErrorsSuite -- -z SPARK-49642"

@deepujain deepujain force-pushed the SPARK-49642-remove-ansi-suggestion-datetime-out-of-bounds branch from 8b93645 to 351cbe0 Compare May 27, 2026 20:02
@deepujain

Copy link
Copy Markdown
Contributor Author

Rebased on current master. Ran ./build/sbt "sql/testOnly org.apache.spark.sql.errors.QueryExecutionAnsiErrorsSuite -- -z SPARK-49642" and the SQLQueryTestSuite date/timestamp/datetime-legacy/timestamp-ansi filters - passed. Ready for CI.

@MaxGekk MaxGekk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 blocking, 0 non-blocking, 0 nits. Correct approach, but the now-duplicate helper needs to be cleaned up before merging.

Design / architecture (1)

  • sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala:308: ansiDateTimeArgumentOutOfRangeWithoutSuggestion is now identical to this method — see inline

messageParameters = Map(
"rangeMessage" -> e.getMessage,
"ansiConfig" -> toSQLConf(SQLConf.ANSI_ENABLED.key)),
errorClass = "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this change, ansiDateTimeArgumentOutOfRangeWithoutSuggestion (lines 315–322) has an identical implementation to this method — same errorClass, same messageParameters, same context/summary/cause. The only remaining difference is the parameter type (Throwable vs Exception). The WithoutSuggestion suffix used to encode a real behavioral distinction; that distinction is gone now that both methods throw WITHOUT_SUGGESTION.

Suggested fix (self-contained in this PR):

  1. Widen this method's parameter to Throwable (all callers pass DateTimeException/RuntimeException, compatible on both the Java and Scala sides).
  2. Delete ansiDateTimeArgumentOutOfRangeWithoutSuggestion (lines 315–322).
  3. Replace its 3 call sites in DateTimeUtils.scala (lines 940, 955, 957) with ansiDateTimeArgumentOutOfRange.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed this by widening ansiDateTimeArgumentOutOfRange to Throwable, deleting ansiDateTimeArgumentOutOfRangeWithoutSuggestion, and switching the three DateTimeUtils call sites over. Rebased on current master and reran ./build/sbt "sql/testOnly org.apache.spark.sql.errors.QueryExecutionAnsiErrorsSuite -- -z SPARK-49642" plus ./build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z time.sql" - both passed.

@deepujain deepujain force-pushed the SPARK-49642-remove-ansi-suggestion-datetime-out-of-bounds branch from 351cbe0 to 39325ab Compare June 14, 2026 16:41

@MaxGekk MaxGekk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 addressed, 0 remaining, 0 new.
0 blocking, 0 non-blocking, 0 nits.

The prior blocking finding (duplicate ansiDateTimeArgumentOutOfRange* helpers) is resolved — merged into a single ansiDateTimeArgumentOutOfRange(e: Throwable). Verified the behavior change reaches all callers: the make_date/make_timestamp sites in DateTimeExpressionUtils.java (which the PR doesn't touch) auto-rebind to the merged (Throwable) method and now emit WITHOUT_SUGGESTION — exactly what the updated golden files reflect. Golden-file coverage is complete, no imports are orphaned by dropping the toSQLConf(SQLConf...) call, QueryExecutionErrors is private[sql] (no public-API impact), and the new QueryExecutionAnsiErrorsSuite test covers the path end-to-end. LGTM.

PR description suggestions

  • The description says "No new tests added", but the diff adds the SPARK-49642: DATETIME_FIELD_OUT_OF_BOUNDS does not suggest ANSI config test to QueryExecutionAnsiErrorsSuite. The test is a good addition — just update that line of the description.

@deepujain deepujain force-pushed the SPARK-49642-remove-ansi-suggestion-datetime-out-of-bounds branch from 39325ab to b3fc7a1 Compare June 26, 2026 15:38
@deepujain

Copy link
Copy Markdown
Contributor Author

Rebased this on current master and updated the PR description to mention the new QueryExecutionAnsiErrorsSuite regression test. I reran ./build/sbt "sql/testOnly org.apache.spark.sql.errors.QueryExecutionAnsiErrorsSuite -- -z SPARK-49642" and ./build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z time.sql" locally; both passed. Ready for CI.

@MaxGekk MaxGekk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All prior items resolved; 0 new. (0 blocking, 0 non-blocking, 0 nits.)

  • The earlier blocking finding (duplicate ansiDateTimeArgumentOutOfRange* helpers) is resolved — a single ansiDateTimeArgumentOutOfRange(Throwable)WITHOUT_SUGGESTION, with the 3 DateTimeUtils sites rebinding to it.
  • My prior PR-description suggestion is addressed — the description now mentions the new QueryExecutionAnsiErrorsSuite regression test.

Re-verified the 9-file change on the rebased head: no source references to the removed DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION remain, the error entry is well-formed (single WITHOUT_SUGGESTION subclass, sqlState 22023), the golden files are consistent, and the regression test asserts the message no longer contains spark.sql.ansi.enabled. Clean rebase (no scope pollution). LGTM.

@MaxGekk MaxGekk changed the title [SPARK-49642][SQL] Remove the ANSI config suggestion in DATETIME_FIEL… [SPARK-49642][SQL] Remove the ANSI config suggestion in DATETIME_FIELD_OUT_OF_BOUNDS Jul 1, 2026
@MaxGekk

MaxGekk commented Jul 1, 2026

Copy link
Copy Markdown
Member

+1, LGTM. Merging to master/4.x.
Thank you, @deepujain.

@MaxGekk MaxGekk closed this in 890ce8d Jul 1, 2026
MaxGekk pushed a commit that referenced this pull request Jul 1, 2026
…D_OUT_OF_BOUNDS

## Summary

In Spark 4.0.0 ANSI mode is on by default. The JIRA asks to minimize suggestions that tell users to turn ANSI off. The error `DATETIME_FIELD_OUT_OF_BOUNDS` previously had a subclass `WITH_SUGGESTION` that appended "If necessary set spark.sql.ansi.enabled to false to bypass this error." This PR removes that suggestion; users can use `try_*` functions for safe behavior instead. The error now always uses `WITHOUT_SUGGESTION` (message is just the range description).

## Change

- **error-conditions.json**: Removed the `WITH_SUGGESTION` subclass from `DATETIME_FIELD_OUT_OF_BOUNDS` (kept only `WITHOUT_SUGGESTION`).
- **QueryExecutionErrors.scala**: `ansiDateTimeArgumentOutOfRange` now throws `DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION` with only `rangeMessage` (removed `ansiConfig` parameter).
- **SQL test result files** (date.sql.out, timestamp.sql.out, timestampNTZ/timestamp-ansi.sql.out, postgreSQL/date.sql.out, datetime-legacy.sql.out): Updated expected error class from `WITH_SUGGESTION` to `WITHOUT_SUGGESTION` and removed `ansiConfig` from expected messageParameters where the error is `DATETIME_FIELD_OUT_OF_BOUNDS`.
- **QueryExecutionAnsiErrorsSuite.scala**: Added a regression test for `DATETIME_FIELD_OUT_OF_BOUNDS` so the error does not suggest disabling ANSI mode.

## Tests

Added `SPARK-49642: DATETIME_FIELD_OUT_OF_BOUNDS does not suggest ANSI config` in `QueryExecutionAnsiErrorsSuite`.

Local validation:

- `./build/sbt "sql/testOnly org.apache.spark.sql.errors.QueryExecutionAnsiErrorsSuite -- -z SPARK-49642"` passed.
- `./build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z time.sql"` passed.

Fixes SPARK-49642

**JIRA assignee for credit:** deepujain

Closes #54695 from deepujain/SPARK-49642-remove-ansi-suggestion-datetime-out-of-bounds.

Authored-by: Deepak Jain <deepujain@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
(cherry picked from commit 890ce8d)
Signed-off-by: Max Gekk <max.gekk@gmail.com>
@MaxGekk

MaxGekk commented Jul 1, 2026

Copy link
Copy Markdown
Member

Merge summary (posted by merge_spark_pr.py):

@MaxGekk

MaxGekk commented Jul 1, 2026

Copy link
Copy Markdown
Member

@deepujain Congratulations with your first contribution to Apache Spark!

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.

2 participants