improved odps sql parser support

This commit is contained in:
高铁
2021-06-28 20:58:45 +08:00
parent 6714647eb3
commit 92a84e9b71
12 changed files with 173 additions and 22 deletions
@@ -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();