@@ -57,6 +57,7 @@ public class QueryParser {
5757 private static final String MULTILINE_COMMENT_END = "*/" ;
5858 private static final String DOUBLE_QUOTES_STRING = "''" ;
5959 private static final String ESCAPED_QUOTE_STRING = "\\ '" ;
60+ private static final String ESCAPED_BACKTICK_STRING = "\\ `" ;
6061
6162 private final String uri ;
6263 private final String schema ;
@@ -193,7 +194,8 @@ static String extractTableName(String query) {
193194 } else if (MULTILINE_COMMENT_BEGIN .equals (nextTwo )) {
194195 int newIdx = query .indexOf (MULTILINE_COMMENT_END , i );
195196 i = newIdx != -1 ? newIdx + 1 : len ;
196- } else if (DOUBLE_QUOTES_STRING .equals (nextTwo ) || ESCAPED_QUOTE_STRING .equals (nextTwo )) {
197+ } else if (DOUBLE_QUOTES_STRING .equals (nextTwo ) || ESCAPED_QUOTE_STRING .equals (nextTwo )
198+ || ESCAPED_BACKTICK_STRING .equals (nextTwo )) {
197199 // ignore escaped single quote
198200 i += nextTwo .length () - 1 ;
199201 } else if (nextTwo .charAt (0 ) == '\'' ) {
@@ -331,23 +333,15 @@ static String normalizeQuery(String query) {
331333 if (index > 0 && len > (index = index + EXPR_FROM .length ())) {
332334 // assume quote is just one character and it always exists
333335 char quote = query .charAt (index ++);
336+ boolean isQuote = quote == '"' || quote == '`' ;
334337
335- int dotIndex = query .indexOf ('.' , index );
338+ int dotIndex = isQuote ? query .indexOf ('.' , index ) : - 1 ;
336339
337- if (dotIndex > index && len > dotIndex && query .charAt (dotIndex - 1 ) == quote
338- && query . charAt ( dotIndex + 1 ) == quote ) { // has schema
340+ if (dotIndex > index && query . charAt ( dotIndex - 1 ) == quote && query .charAt (dotIndex + 1 ) == quote ) { // has
341+ // schema
339342 dotIndex += 2 ;
340- /*
341- * int endIndex = query.indexOf(quote, dotIndex); // .lastIndexOf(quote); if
342- * (endIndex > dotIndex) { extractedQuery = query.substring(dotIndex, endIndex);
343- * }
344- */
345- } else if (quote == '"' || quote == '`' ) {
343+ } else if (isQuote ) {
346344 dotIndex = index ;
347- /*
348- * int endIndex = query.indexOf(quote, index); // query.lastIndexOf(quote); if
349- * (endIndex > index) { extractedQuery = query.substring(index, endIndex); }
350- */
351345 } else {
352346 dotIndex = len ;
353347 }
@@ -362,7 +356,8 @@ static String normalizeQuery(String query) {
362356 } else if (MULTILINE_COMMENT_BEGIN .equals (nextTwo )) {
363357 int newIdx = query .indexOf (MULTILINE_COMMENT_END , i );
364358 i = newIdx != -1 ? newIdx + 1 : len ;
365- } else if (DOUBLE_QUOTES_STRING .equals (nextTwo ) || ESCAPED_QUOTE_STRING .equals (nextTwo )) {
359+ } else if (DOUBLE_QUOTES_STRING .equals (nextTwo ) || ESCAPED_QUOTE_STRING .equals (nextTwo )
360+ || ESCAPED_BACKTICK_STRING .equals (nextTwo )) {
366361 // ignore escaped single quote
367362 i += nextTwo .length () - 1 ;
368363 } else if (nextTwo .charAt (0 ) == '\'' ) {
@@ -387,6 +382,7 @@ static String normalizeQuery(String query) {
387382 // \f Insert a formfeed in the text at this point.
388383 // \' Insert a single quote character in the text at this point.
389384 // \" Insert a double quote character in the text at this point.
385+ // \` Insert a backtick character in the text at this point.
390386 // \\ Insert a backslash character in the text at this point.
391387 StringBuilder builder = new StringBuilder ();
392388 for (int i = 0 ; i < len ; i ++) {
@@ -422,6 +418,10 @@ static String normalizeQuery(String query) {
422418 builder .append ('"' );
423419 i ++;
424420 break ;
421+ case '`' :
422+ builder .append ('`' );
423+ i ++;
424+ break ;
425425 case '\\' :
426426 builder .append ('\\' );
427427 i ++;
0 commit comments