cloud-fan commented on a change in pull request #34668:
URL: https://github.com/apache/spark/pull/34668#discussion_r755150850
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala
##########
@@ -78,9 +79,30 @@ abstract class AbstractSqlParser extends ParserInterface
with SQLConfHelper with
astBuilder.visitQuery(parser.query())
}
+ /** check `has_unclosed_bracketed_comment` to find out the unclosed
bracketed comment. */
+ private def singleStatementWithCheck(
+ parser: SqlBaseParser, sqlText: String): SingleStatementContext = {
+ val singleStatementContext = parser.singleStatement()
+ assert(parser.getTokenStream.isInstanceOf[CommonTokenStream])
+
+ val tokenStream = parser.getTokenStream.asInstanceOf[CommonTokenStream]
+ assert(tokenStream.getTokenSource.isInstanceOf[SqlBaseLexer])
+
+ val lexer = tokenStream.getTokenSource.asInstanceOf[SqlBaseLexer]
+ if (lexer.has_unclosed_bracketed_comment) {
+ // The last token is 'EOF' and the penultimate is unclosed bracketed
comment
+ val failedToken = tokenStream.get(tokenStream.size() - 2)
+ assert(failedToken.getType() == SqlBaseParser.BRACKETED_COMMENT)
+ val position = Origin(Option(failedToken.getLine),
Option(failedToken.getCharPositionInLine))
+ throw QueryParsingErrors.unclosedBracketedCommentError(sqlText, position)
+ }
+
+ singleStatementContext
+ }
+
/** Creates LogicalPlan for a given SQL string. */
override def parsePlan(sqlText: String): LogicalPlan = parse(sqlText) {
parser =>
- astBuilder.visitSingleStatement(parser.singleStatement()) match {
+ astBuilder.visitSingleStatement(singleStatementWithCheck(parser, sqlText))
match {
Review comment:
Can we check the unclosed comment using a listener in the `parse` method
below?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]