Skip to content

Commit

Permalink
[SPARK-49632][SQL] Remove the ANSI config suggestion in CANNOT_PARSE_…
Browse files Browse the repository at this point in the history
…TIMESTAMP

### What changes were proposed in this pull request?
This PR changes the message returned on a failure of `ToTimestamp` family of expressions.

### Why are the changes needed?
CANNOT_PARSE_TIMESTAMP contains suggested fix for turning off ANSI mode. Now that in Spark 4.0.0 we have moved to ANSI mode on by default, we want to keep suggestions of this kind to the minimum.

### Does this PR introduce _any_ user-facing change?
Yes, error message is changing.

### How was this patch tested?
Existing tests span the error message change.

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

Closes apache#49227 from mihailom-db/cannot_parse_timestamp.

Authored-by: Mihailo Milosevic <mihailo.milosevic@databricks.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
  • Loading branch information
mihailom-db authored and HyukjinKwon committed Dec 18, 2024
1 parent 2b1369b commit 2cb66e6
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
},
"CANNOT_PARSE_TIMESTAMP" : {
"message" : [
"<message>. If necessary set <ansiConfig> to \"false\" to bypass this error."
"<message>. Use `try_to_timestamp` to tolerate invalid input string and return NULL instead."
],
"sqlState" : "22007"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
new SparkDateTimeException(
errorClass = "CANNOT_PARSE_TIMESTAMP",
messageParameters = Map(
"message" -> e.getMessage,
"ansiConfig" -> toSQLConf(SQLConf.ANSI_ENABLED.key)),
"message" -> e.getMessage),
context = Array.empty,
summary = "")
}
Expand Down
1 change: 0 additions & 1 deletion sql/core/src/test/resources/sql-tests/results/date.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Invalid date 'February 29' as '1970' is not a leap year"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"02-29\""
}
}
Expand Down Expand Up @@ -1585,7 +1584,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.\""
}
}
Expand All @@ -1601,7 +1599,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.0\""
}
}
Expand All @@ -1617,7 +1614,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.1\""
}
}
Expand All @@ -1633,7 +1629,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.12\""
}
}
Expand All @@ -1649,7 +1644,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.123UTC\""
}
}
Expand All @@ -1665,7 +1659,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.1234\""
}
}
Expand All @@ -1681,7 +1674,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.12345CST\""
}
}
Expand All @@ -1697,7 +1689,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.123456PST\""
}
}
Expand All @@ -1713,7 +1704,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.1234567PST\""
}
}
Expand All @@ -1729,7 +1719,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"123456 2019-10-06 10:11:12.123456PST\""
}
}
Expand All @@ -1745,7 +1734,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"223456 2019-10-06 10:11:12.123456PST\""
}
}
Expand All @@ -1761,7 +1749,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.1234\""
}
}
Expand All @@ -1777,7 +1764,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.123\""
}
}
Expand All @@ -1793,7 +1779,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12\""
}
}
Expand All @@ -1809,7 +1794,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11:12.12\""
}
}
Expand All @@ -1825,7 +1809,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 10:11\""
}
}
Expand All @@ -1841,7 +1824,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06S10:11:12.12345\""
}
}
Expand All @@ -1857,7 +1839,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"12.12342019-10-06S10:11\""
}
}
Expand All @@ -1873,7 +1854,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"12.1232019-10-06S10:11\""
}
}
Expand All @@ -1889,7 +1869,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"12.1232019-10-06S10:11\""
}
}
Expand All @@ -1905,7 +1884,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"12.1234019-10-06S10:11\""
}
}
Expand Down Expand Up @@ -1977,7 +1955,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"02-29\""
}
}
Expand Down Expand Up @@ -2208,7 +2185,6 @@ org.apache.spark.SparkDateTimeException
"errorClass" : "CANNOT_PARSE_TIMESTAMP",
"sqlState" : "22007",
"messageParameters" : {
"ansiConfig" : "\"spark.sql.ansi.enabled\"",
"message" : "Unparseable date: \"2019-10-06 A\""
}
}
Expand Down
Loading

0 comments on commit 2cb66e6

Please sign in to comment.