Copilot commented on code in PR #19719:
URL: https://github.com/apache/druid/pull/19719#discussion_r3628426747
##########
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParser.java:
##########
@@ -199,6 +204,24 @@ private static DruidException
translateParseException(SqlParseException e)
} else {
final String theUnexpectedToken =
getUnexpectedTokenString(parseException);
+ if
(parserMetadata.isReservedWord(theUnexpectedToken.toUpperCase(Locale.ROOT))) {
+ return InvalidSqlInput
+ .exception(
+ e,
+ "Token [%s] (line [%s], column [%s]) is a reserved keyword. "
+ + "To use it as an identifier, quote it as [\"%s\"]",
+ theUnexpectedToken,
+ failurePosition.getLineNum(),
+ failurePosition.getColumnNum(),
+ theUnexpectedToken
+ )
+ .withContext("line", failurePosition.getLineNum())
+ .withContext("column", failurePosition.getColumnNum())
+ .withContext("endLine", failurePosition.getEndLineNum())
+ .withContext("endColumn", failurePosition.getEndColumnNum())
+ .withContext("token", theUnexpectedToken);
+ }
+
final String[] tokenDictionary = e.getTokenImages();
final int[][] expectedTokenSequences = e.getExpectedTokenSequences();
final ArrayList<String> expectedTokens = new
ArrayList<>(expectedTokenSequences.length);
Review Comment:
The reserved-keyword hint is currently triggered for *any* parse error where
the unexpected token happens to be a reserved word (e.g., `FROM`, `SELECT`,
etc.), even when the parser was not expecting an identifier. This can replace a
correct syntax error with a misleading “quote it as an identifier” message.
Consider gating the hint on whether the expected tokens include identifier
forms (e.g., `<IDENTIFIER>`, `<QUOTED_IDENTIFIER>`, etc.), and also guard
against `parserMetadata` being null.
--
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]