FrankChen021 commented on code in PR #19719:
URL: https://github.com/apache/druid/pull/19719#discussion_r3665456837
##########
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParser.java:
##########
@@ -232,6 +262,57 @@ private static DruidException
translateParseException(SqlParseException e)
return InvalidSqlInput.exception(e.getMessage());
}
+ private static boolean isIdentifierExpected(String[] tokenDictionary,
int[][] expectedTokenSequences)
+ {
+ for (int[] expectedTokenSequence : expectedTokenSequences) {
+ if (expectedTokenSequence.length > 0) {
+ final String token = tokenDictionary[expectedTokenSequence[0]];
+ if ("<IDENTIFIER>".equals(token)
+ || "<QUOTED_IDENTIFIER>".equals(token)
+ || "<BACK_QUOTED_IDENTIFIER>".equals(token)
+ || "<BRACKET_QUOTED_IDENTIFIER>".equals(token)
+ || "<UNICODE_QUOTED_IDENTIFIER>".equals(token)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static boolean isKeywordExpected(
+ String unexpectedToken,
+ String[] tokenDictionary,
+ int[][] expectedTokenSequences
+ )
+ {
+ for (int[] expectedTokenSequence : expectedTokenSequences) {
+ if (expectedTokenSequence.length > 0
+ && unexpectedToken.equalsIgnoreCase(
+
SqlParserUtil.getTokenVal(tokenDictionary[expectedTokenSequence[0]])
+ )) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean isFunctionCall(String sql, SqlParserPos
failurePosition, String token)
+ {
+ int tokenEndOffset = 0;
+ for (int line = 1; line < failurePosition.getLineNum(); line++) {
+ tokenEndOffset = sql.indexOf('\n', tokenEndOffset) + 1;
+ if (tokenEndOffset == 0) {
+ return false;
+ }
+ }
+
+ tokenEndOffset += failurePosition.getColumnNum() - 1 + token.length();
+ while (tokenEndOffset < sql.length() &&
Character.isWhitespace(sql.charAt(tokenEndOffset))) {
Review Comment:
[P2] Skip SQL comments when detecting function calls
`isFunctionCall` skips only whitespace, but SQL comments are also valid
separators before `(`. For example, `SELECT strlen(unnest /* comment */
(a_int))` now reports that `unnest` is a reserved identifier and recommends
quoting it, despite it being used in a function-call context. Skip line/block
comments or use lexer token boundaries, and add regression coverage.
--
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]