Skip to content

Commit

Permalink
[SPARK-50069][SQL] Integrate _LEGACY_ERROR_TEMP_0028 into `UNSUPPOR…
Browse files Browse the repository at this point in the history
…TED_FROM_TO_EXPRESSION`

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

This PR proposes to Integrate `_LEGACY_ERROR_TEMP_0028` into `UNSUPPORTED_FROM_TO_EXPRESSION`

### Why are the changes needed?

To improve the error message by assigning proper error condition and SQLSTATE

### Does this PR introduce _any_ user-facing change?

No, only user-facing error message improved

### How was this patch tested?

Updated the existing tests

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

No

Closes #48597 from itholic/LEGACY_0028.

Authored-by: Haejoon Lee <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
  • Loading branch information
itholic authored and MaxGekk committed Oct 29, 2024
1 parent 56593f4 commit bb29a3f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
5 changes: 0 additions & 5 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5760,11 +5760,6 @@
"The value of from-to unit must be a string."
]
},
"_LEGACY_ERROR_TEMP_0028" : {
"message" : [
"Intervals FROM <from> TO <to> are not supported."
]
},
"_LEGACY_ERROR_TEMP_0029" : {
"message" : [
"Cannot mix year-month and day-time fields: <literal>."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,16 @@ private[sql] object QueryParsingErrors extends DataTypeErrorsBase {
from: String,
to: String,
ctx: ParserRuleContext): Throwable = {
val intervalInput = ctx.getText()
val pattern = "'([^']*)'".r
val input = pattern.findFirstMatchIn(intervalInput) match {
case Some(m) => m.group(1)
case None => ""
}

new ParseException(
errorClass = "_LEGACY_ERROR_TEMP_0028",
messageParameters = Map("from" -> from, "to" -> to),
errorClass = "INVALID_INTERVAL_FORMAT.UNSUPPORTED_FROM_TO_EXPRESSION",
messageParameters = Map("input" -> input, "from" -> from, "to" -> to),
ctx)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,8 @@ class ExpressionParserSuite extends AnalysisTest {
// Unknown FROM TO intervals
checkError(
exception = parseException("interval '10' month to second"),
condition = "_LEGACY_ERROR_TEMP_0028",
parameters = Map("from" -> "month", "to" -> "second"),
condition = "INVALID_INTERVAL_FORMAT.UNSUPPORTED_FROM_TO_EXPRESSION",
parameters = Map("input" -> "10", "from" -> "month", "to" -> "second"),
context = ExpectedContext(
fragment = "'10' month to second",
start = 9,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,9 +1233,11 @@ select interval '1' year to second
-- !query analysis
org.apache.spark.sql.catalyst.parser.ParseException
{
"errorClass" : "_LEGACY_ERROR_TEMP_0028",
"errorClass" : "INVALID_INTERVAL_FORMAT.UNSUPPORTED_FROM_TO_EXPRESSION",
"sqlState" : "22006",
"messageParameters" : {
"from" : "year",
"input" : "1",
"to" : "second"
},
"queryContext" : [ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,9 +1233,11 @@ select interval '1' year to second
-- !query analysis
org.apache.spark.sql.catalyst.parser.ParseException
{
"errorClass" : "_LEGACY_ERROR_TEMP_0028",
"errorClass" : "INVALID_INTERVAL_FORMAT.UNSUPPORTED_FROM_TO_EXPRESSION",
"sqlState" : "22006",
"messageParameters" : {
"from" : "year",
"input" : "1",
"to" : "second"
},
"queryContext" : [ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1535,9 +1535,11 @@ struct<>
-- !query output
org.apache.spark.sql.catalyst.parser.ParseException
{
"errorClass" : "_LEGACY_ERROR_TEMP_0028",
"errorClass" : "INVALID_INTERVAL_FORMAT.UNSUPPORTED_FROM_TO_EXPRESSION",
"sqlState" : "22006",
"messageParameters" : {
"from" : "year",
"input" : "1",
"to" : "second"
},
"queryContext" : [ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1422,9 +1422,11 @@ struct<>
-- !query output
org.apache.spark.sql.catalyst.parser.ParseException
{
"errorClass" : "_LEGACY_ERROR_TEMP_0028",
"errorClass" : "INVALID_INTERVAL_FORMAT.UNSUPPORTED_FROM_TO_EXPRESSION",
"sqlState" : "22006",
"messageParameters" : {
"from" : "year",
"input" : "1",
"to" : "second"
},
"queryContext" : [ {
Expand Down

0 comments on commit bb29a3f

Please sign in to comment.