From 1b773dcd878368998c76e41e13c8b43b953f2e21 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 15 May 2018 16:51:16 +0100 Subject: [PATCH] Improve ParseError stop location when offending symbol is a token In the case where the offending symbol is a CommonToken, this PR increases the accuracy of the start and stop origin by leveraging the start and stop index information from CommonToken. --- .../spark/sql/catalyst/parser/ParseDriver.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala index 4c20f2368bded..111c70c833d5c 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala @@ -192,8 +192,16 @@ case object ParseErrorListener extends BaseErrorListener { charPositionInLine: Int, msg: String, e: RecognitionException): Unit = { - val position = Origin(Some(line), Some(charPositionInLine)) - throw new ParseException(None, msg, position, position) + val (start, stop) = offendingSymbol match { + case token: CommonToken => + val start = Origin (Some (line), Some (token.getStartIndex) ) + val stop = Origin (Some (line), Some (token.getStopIndex) ) + (start, stop) + case _ => + val start = Origin (Some (line), Some (charPositionInLine) ) + (start, start) + } + throw new ParseException (None, msg, start, stop) } }