Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-50069][SQL] Integrate _LEGACY_ERROR_TEMP_0028 into UNSUPPORTED_FROM_TO_EXPRESSION #48597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -5713,11 +5713,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 @@ -111,7 +111,14 @@ class DataTypeAstBuilder extends SqlBaseParserBaseVisitor[AnyRef] {
val endStr = ctx.to.getText.toLowerCase(Locale.ROOT)
val end = YearMonthIntervalType.stringToField(endStr)
if (end <= start) {
throw QueryParsingErrors.fromToIntervalUnsupportedError(startStr, endStr, ctx)
val intervalInput = ctx.getText()
val pattern = "'([^']*)'".r

val input = pattern.findFirstMatchIn(intervalInput) match {
case Some(m) => m.group(1)
case None => ""
}
throw QueryParsingErrors.fromToIntervalUnsupportedError(input, startStr, endStr, ctx)
}
YearMonthIntervalType(start, end)
} else {
Expand All @@ -126,7 +133,14 @@ class DataTypeAstBuilder extends SqlBaseParserBaseVisitor[AnyRef] {
val endStr = ctx.to.getText.toLowerCase(Locale.ROOT)
val end = DayTimeIntervalType.stringToField(endStr)
if (end <= start) {
throw QueryParsingErrors.fromToIntervalUnsupportedError(startStr, endStr, ctx)
val intervalInput = ctx.getText()
val pattern = "'([^']*)'".r

val input = pattern.findFirstMatchIn(intervalInput) match {
case Some(m) => m.group(1)
case None => ""
}
throw QueryParsingErrors.fromToIntervalUnsupportedError(input, startStr, endStr, ctx)
}
DayTimeIntervalType(start, end)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ private[sql] object QueryParsingErrors extends DataTypeErrorsBase {
}

def fromToIntervalUnsupportedError(
input: String,
from: String,
to: String,
ctx: ParserRuleContext): Throwable = {
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 @@ -3570,7 +3570,14 @@ class AstBuilder extends DataTypeAstBuilder
IntervalUtils.fromDayTimeString(value,
DayTimeIntervalType.stringToField(from), DayTimeIntervalType.stringToField(to))
case _ =>
throw QueryParsingErrors.fromToIntervalUnsupportedError(from, to, ctx)
val intervalInput = ctx.getText()
val pattern = "'([^']*)'".r

val input = pattern.findFirstMatchIn(intervalInput) match {
case Some(m) => m.group(1)
case None => ""
}
throw QueryParsingErrors.fromToIntervalUnsupportedError(input, from, to, ctx)
}
} catch {
// Keep error class of SparkIllegalArgumentExceptions and enrich it with query context
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