FrankChen021 commented on code in PR #19719:
URL: https://github.com/apache/druid/pull/19719#discussion_r3644309593
##########
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:
Fixed in a40f7d4559. The specialized hint now requires an identifier token
to be expected at the current parse position, includes the defensive metadata
null check, and retains the generic parser diagnostic otherwise.
##########
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))) {
Review Comment:
Fixed in a40f7d4559. The hint is now gated on identifier context, and a
regression test verifies that SELECT * FROM foo GROUP ORDER BY x retains the
normal unexpected-token error for ORDER.
--
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]