mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved odps sql parser support
This commit is contained in:
@@ -675,17 +675,33 @@ public class Lexer {
|
||||
ch = charAt(++pos);
|
||||
}
|
||||
|
||||
if (ch == '/' && pos + 1 < text.length() && text.charAt(pos + 1) == '*') {
|
||||
int index = text.indexOf("*/", pos + 2);
|
||||
if (index == -1) {
|
||||
return SQLType.UNKNOWN;
|
||||
}
|
||||
if (ch == '/') {
|
||||
if (pos + 1 < text.length() && text.charAt(pos + 1) == '*') {
|
||||
int index = text.indexOf("*/", pos + 2);
|
||||
if (index == -1) {
|
||||
return SQLType.UNKNOWN;
|
||||
}
|
||||
|
||||
pos = index + 2;
|
||||
ch = charAt(pos);
|
||||
continue;
|
||||
pos = index + 2;
|
||||
ch = charAt(pos);
|
||||
continue;
|
||||
} else if (pos + 2 < text.length()
|
||||
&& text.charAt(pos + 1) == ' '
|
||||
&& text.charAt(pos + 2) == '*'
|
||||
&& dbType == DbType.odps
|
||||
) {
|
||||
int index = text.indexOf("* /", pos + 3);
|
||||
if (index == -1) {
|
||||
return SQLType.UNKNOWN;
|
||||
}
|
||||
|
||||
pos = index + 3;
|
||||
ch = charAt(pos);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ch == '-' && pos + 1 < text.length() && text.charAt(pos + 1) == '-') {
|
||||
int index = text.indexOf('\n', pos + 2);
|
||||
if (index == -1) {
|
||||
@@ -1181,6 +1197,12 @@ public class Lexer {
|
||||
bufPos = 0;
|
||||
continue;
|
||||
}
|
||||
} else if (nextChar == ' ' && charAt(pos + 2) == ' ' && charAt(pos + 3) == '*') {
|
||||
scanComment();
|
||||
if ((token == Token.LINE_COMMENT || token == Token.MULTI_LINE_COMMENT) && skipComment) {
|
||||
bufPos = 0;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
token = Token.SLASH;
|
||||
scanChar();
|
||||
@@ -2091,6 +2113,12 @@ public class Lexer {
|
||||
mark = pos;
|
||||
bufPos = 0;
|
||||
scanChar();
|
||||
|
||||
if (dbType == DbType.odps && ch == ' ') {
|
||||
mark = pos;
|
||||
bufPos = 0;
|
||||
scanChar();
|
||||
}
|
||||
}
|
||||
|
||||
// /*+ */
|
||||
@@ -2114,13 +2142,20 @@ public class Lexer {
|
||||
for (;;) {
|
||||
char c2;
|
||||
if (ch == '*'
|
||||
&& ((c2 = charAt(pos + 1)) == '/' || (c2 == ' ' && charAt(pos + 2) == '/'))
|
||||
&& ((c2 = charAt(pos + 1)) == '/'
|
||||
|| (c2 == ' ' && charAt(pos + 2) == '/')
|
||||
|| (c2 == ' ' && charAt(pos + 2) == ' ' && charAt(pos + 3) == '/'))
|
||||
) {
|
||||
if (c2 == ' ') {
|
||||
bufPos ++;
|
||||
scanChar();
|
||||
}
|
||||
|
||||
if (charAt(pos + 1) == ' ') {
|
||||
bufPos ++;
|
||||
scanChar();
|
||||
}
|
||||
|
||||
bufPos += 2;
|
||||
scanChar();
|
||||
scanChar();
|
||||
|
||||
Reference in New Issue
Block a user