This is an automated email from the ASF dual-hosted git repository.
MaxGekk pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new 565144b395e9 [SPARK-49642][SQL] Remove the ANSI config suggestion in
DATETIME_FIELD_OUT_OF_BOUNDS
565144b395e9 is described below
commit 565144b395e95413ba183aaabf6b4f5545a7b44f
Author: Deepak Jain <[email protected]>
AuthorDate: Wed Jul 1 12:33:23 2026 +0200
[SPARK-49642][SQL] Remove the ANSI config suggestion in
DATETIME_FIELD_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 <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
(cherry picked from commit 890ce8d6d56db862d76060f01d2a2f510dac6ce0)
Signed-off-by: Max Gekk <[email protected]>
---
.../src/main/resources/error/error-conditions.json | 5 -----
.../apache/spark/sql/catalyst/util/DateTimeUtils.scala | 6 +++---
.../apache/spark/sql/errors/QueryExecutionErrors.scala | 13 +------------
.../src/test/resources/sql-tests/results/date.sql.out | 6 ++----
.../resources/sql-tests/results/datetime-legacy.sql.out | 15 +++++----------
.../resources/sql-tests/results/postgreSQL/date.sql.out | 9 +++------
.../test/resources/sql-tests/results/timestamp.sql.out | 9 +++------
.../results/timestampNTZ/timestamp-ansi.sql.out | 9 +++------
.../sql/errors/QueryExecutionAnsiErrorsSuite.scala | 17 +++++++++++++++++
9 files changed, 37 insertions(+), 52 deletions(-)
diff --git a/common/utils/src/main/resources/error/error-conditions.json
b/common/utils/src/main/resources/error/error-conditions.json
index c66c1c5e9cc4..08666ad314fc 100644
--- a/common/utils/src/main/resources/error/error-conditions.json
+++ b/common/utils/src/main/resources/error/error-conditions.json
@@ -2128,11 +2128,6 @@
"message" : [
""
]
- },
- "WITH_SUGGESTION" : {
- "message" : [
- "If necessary set <ansiConfig> to \"false\" to bypass this error."
- ]
}
},
"sqlState" : "22023"
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
index 6fcb6c3075ed..be2cc6098e73 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
@@ -1030,7 +1030,7 @@ object DateTimeUtils extends SparkDateTimeUtils {
localTimeToNanos(lt)
} catch {
case e @ (_: DateTimeException | _: ArithmeticException) =>
- throw
QueryExecutionErrors.ansiDateTimeArgumentOutOfRangeWithoutSuggestion(e)
+ throw QueryExecutionErrors.ansiDateTimeArgumentOutOfRange(e)
}
}
@@ -1045,9 +1045,9 @@ object DateTimeUtils extends SparkDateTimeUtils {
nanos
} catch {
case e: DateTimeException =>
- throw
QueryExecutionErrors.ansiDateTimeArgumentOutOfRangeWithoutSuggestion(e)
+ throw QueryExecutionErrors.ansiDateTimeArgumentOutOfRange(e)
case e: ArithmeticException =>
- throw
QueryExecutionErrors.ansiDateTimeArgumentOutOfRangeWithoutSuggestion(
+ throw QueryExecutionErrors.ansiDateTimeArgumentOutOfRange(
new DateTimeException("Overflow in TIME conversion", e))
}
}
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
index b5966a7ed3ac..fda9cc9b2181 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
@@ -303,18 +303,7 @@ private[sql] object QueryExecutionErrors extends
QueryErrorsBase with ExecutionE
cause = Some(e))
}
- def ansiDateTimeArgumentOutOfRange(e: Exception): SparkDateTimeException = {
- new SparkDateTimeException(
- errorClass = "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
- messageParameters = Map(
- "rangeMessage" -> e.getMessage,
- "ansiConfig" -> toSQLConf(SQLConf.ANSI_ENABLED.key)),
- context = Array.empty,
- summary = "",
- cause = Some(e))
- }
-
- def ansiDateTimeArgumentOutOfRangeWithoutSuggestion(e: Throwable):
SparkDateTimeException = {
+ def ansiDateTimeArgumentOutOfRange(e: Throwable): SparkDateTimeException = {
new SparkDateTimeException(
errorClass = "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
messageParameters = Map("rangeMessage" -> e.getMessage),
diff --git a/sql/core/src/test/resources/sql-tests/results/date.sql.out
b/sql/core/src/test/resources/sql-tests/results/date.sql.out
index 533795da1c49..d202a61e7d91 100644
--- a/sql/core/src/test/resources/sql-tests/results/date.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/date.sql.out
@@ -53,10 +53,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for MonthOfYear (valid values 1 - 12): 13"
}
}
@@ -69,10 +68,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for DayOfMonth (valid values 1 - 28/31):
33"
}
}
diff --git
a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out
b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out
index 15dc59557d37..7705d2b4d3d7 100644
--- a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out
@@ -53,10 +53,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for MonthOfYear (valid values 1 - 12): 13"
}
}
@@ -69,10 +68,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for DayOfMonth (valid values 1 - 28/31):
33"
}
}
@@ -1347,10 +1345,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59):
61"
}
}
@@ -1379,10 +1376,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59):
99"
}
}
@@ -1395,10 +1391,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59):
999"
}
}
diff --git
a/sql/core/src/test/resources/sql-tests/results/postgreSQL/date.sql.out
b/sql/core/src/test/resources/sql-tests/results/postgreSQL/date.sql.out
index 7dc53d2f264e..22ecf7f4ce7f 100755
--- a/sql/core/src/test/resources/sql-tests/results/postgreSQL/date.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/postgreSQL/date.sql.out
@@ -687,10 +687,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid date 'FEBRUARY 30'"
}
}
@@ -703,10 +702,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for MonthOfYear (valid values 1 - 12): 13"
}
}
@@ -719,10 +717,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for DayOfMonth (valid values 1 - 28/31):
-1"
}
}
diff --git a/sql/core/src/test/resources/sql-tests/results/timestamp.sql.out
b/sql/core/src/test/resources/sql-tests/results/timestamp.sql.out
index 2c0293e79f6a..9a4d9bc4391d 100644
--- a/sql/core/src/test/resources/sql-tests/results/timestamp.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/timestamp.sql.out
@@ -154,10 +154,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59):
61"
}
}
@@ -186,10 +185,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59):
99"
}
}
@@ -202,10 +200,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59):
999"
}
}
diff --git
a/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp-ansi.sql.out
b/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp-ansi.sql.out
index 86c485870e79..76552bb5b61f 100644
---
a/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp-ansi.sql.out
+++
b/sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp-ansi.sql.out
@@ -154,10 +154,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59):
61"
}
}
@@ -186,10 +185,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59):
99"
}
}
@@ -202,10 +200,9 @@ struct<>
-- !query output
org.apache.spark.SparkDateTimeException
{
- "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION",
+ "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
"sqlState" : "22023",
"messageParameters" : {
- "ansiConfig" : "\"spark.sql.ansi.enabled\"",
"rangeMessage" : "Invalid value for SecondOfMinute (valid values 0 - 59):
999"
}
}
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala
index 7d8e23546ca2..d5185289e021 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala
@@ -127,6 +127,23 @@ class QueryExecutionAnsiErrorsSuite extends
SharedSparkSession {
))
}
+ test("SPARK-49642: DATETIME_FIELD_OUT_OF_BOUNDS does not suggest ANSI
config") {
+ checkError(
+ exception = intercept[SparkDateTimeException] {
+ sql("select make_date(2000, 13, 1)").collect()
+ },
+ condition = "DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION",
+ sqlState = "22023",
+ parameters = Map("rangeMessage" -> "Invalid value for MonthOfYear (valid
values 1 - 12): 13"))
+ // Ensure message does not contain the removed ANSI bypass suggestion
+ val e = intercept[SparkDateTimeException] {
+ sql("select make_date(2000, 1, 33)").collect()
+ }
+ assert(e.getCondition ===
"DATETIME_FIELD_OUT_OF_BOUNDS.WITHOUT_SUGGESTION")
+ assert(!e.getMessage.contains("spark.sql.ansi.enabled"))
+ assert(!e.getMessage.contains("to \"false\" to bypass"))
+ }
+
test("NUMERIC_VALUE_OUT_OF_RANGE: cast string to decimal") {
checkError(
exception = intercept[SparkArithmeticException] {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]