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-51722][SQL] Remove "stop" origin from ParseException #50518

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ abstract class AbstractParser extends DataTypeParserInterface with Logging {
throw new ParseException(
command = Option(command),
start = e.origin,
stop = e.origin,
errorClass = e.getCondition,
messageParameters = e.getMessageParameters.asScala.toMap,
queryContext = e.getQueryContext)
Expand Down Expand Up @@ -158,24 +157,19 @@ case object ParseErrorListener extends BaseErrorListener {
charPositionInLine: Int,
msg: String,
e: RecognitionException): Unit = {
val (start, stop) = offendingSymbol match {
val start = offendingSymbol match {
case token: CommonToken =>
val start = Origin(Some(line), Some(token.getCharPositionInLine))
val length = token.getStopIndex - token.getStartIndex + 1
val stop = Origin(Some(line), Some(token.getCharPositionInLine + length))
(start, stop)
Origin(Some(line), Some(token.getCharPositionInLine))
case _ =>
val start = Origin(Some(line), Some(charPositionInLine))
(start, start)
Origin(Some(line), Some(charPositionInLine))
}
e match {
case sre: SparkRecognitionException if sre.errorClass.isDefined =>
throw new ParseException(None, start, stop, sre.errorClass.get, sre.messageParameters)
throw new ParseException(None, start, sre.errorClass.get, sre.messageParameters)
case _ =>
throw new ParseException(
command = None,
start = start,
stop = stop,
Copy link
Member

Choose a reason for hiding this comment

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

Oh, ParseException doesn't use stop actually.

Copy link
Member Author

Choose a reason for hiding this comment

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

@viirya yes, for parser exception we just shall the start position with 3 ^s

errorClass = "PARSE_SYNTAX_ERROR",
messageParameters = Map("error" -> msg, "hint" -> ""))
}
Expand All @@ -190,7 +184,6 @@ class ParseException private (
val command: Option[String],
message: String,
val start: Origin,
val stop: Origin,
errorClass: Option[String] = None,
messageParameters: Map[String, String] = Map.empty,
queryContext: Array[QueryContext] = ParseException.getQueryContext())
Expand All @@ -208,40 +201,36 @@ class ParseException private (
Option(SparkParserUtils.command(ctx)),
SparkThrowableHelper.getMessage(errorClass, messageParameters),
SparkParserUtils.position(ctx.getStart),
SparkParserUtils.position(ctx.getStop),
Some(errorClass),
messageParameters)

def this(errorClass: String, ctx: ParserRuleContext) = this(errorClass, Map.empty, ctx)
def this(errorClass: String, ctx: ParserRuleContext) =
this(errorClass = errorClass, messageParameters = Map.empty, ctx = ctx)

/** Compose the message through SparkThrowableHelper given errorClass and messageParameters. */
def this(
command: Option[String],
start: Origin,
stop: Origin,
errorClass: String,
messageParameters: Map[String, String]) =
this(
command,
SparkThrowableHelper.getMessage(errorClass, messageParameters),
start,
stop,
Some(errorClass),
messageParameters,
queryContext = ParseException.getQueryContext())

def this(
command: Option[String],
start: Origin,
stop: Origin,
errorClass: String,
messageParameters: Map[String, String],
queryContext: Array[QueryContext]) =
this(
command,
SparkThrowableHelper.getMessage(errorClass, messageParameters),
start,
stop,
Some(errorClass),
messageParameters,
queryContext)
Expand Down Expand Up @@ -282,7 +271,7 @@ class ParseException private (
} else {
(cl, messageParameters)
}
new ParseException(Option(cmd), start, stop, newCl, params, queryContext)
new ParseException(Option(cmd), start, newCl, params, queryContext)
}

override def getQueryContext: Array[QueryContext] = queryContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ private[sql] object QueryParsingErrors extends DataTypeErrorsBase {
new ParseException(
command = Option(sqlText),
start = position,
stop = position,
errorClass = "INVALID_SQL_SYNTAX.UNSUPPORTED_SQL_STATEMENT",
messageParameters = Map("sqlText" -> sqlText))
}
Expand Down Expand Up @@ -632,7 +631,6 @@ private[sql] object QueryParsingErrors extends DataTypeErrorsBase {
new ParseException(
command = origin.sqlText,
start = origin,
stop = origin,
errorClass = "UNSUPPORTED_FEATURE.PARAMETER_MARKER_IN_UNEXPECTED_STATEMENT",
messageParameters = Map("statement" -> statement))
}
Expand Down Expand Up @@ -690,7 +688,6 @@ private[sql] object QueryParsingErrors extends DataTypeErrorsBase {
new ParseException(
command = Some(command),
start = start,
stop = stop,
errorClass = "UNCLOSED_BRACKETED_COMMENT",
messageParameters = Map.empty)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,6 @@ class AstBuilder extends DataTypeAstBuilder
throw new ParseException(
command = Some(SparkParserUtils.command(n)),
start = Origin(),
stop = Origin(),
errorClass = "PARSE_SYNTAX_ERROR",
messageParameters = Map(
"error" -> s"'$error'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ private[client] object GrpcExceptionConverter {
new ParseException(
None,
Origin(),
Origin(),
errorClass = params.errorClass.orNull,
messageParameters = params.messageParameters,
queryContext = params.queryContext)),
Expand Down