improved sql parser.

This commit is contained in:
wenshao
2017-08-10 14:50:10 +08:00
parent 1c900720d8
commit 52bb3da616
4 changed files with 90 additions and 12 deletions
@@ -284,6 +284,11 @@ public class SQLSelectParser extends SQLParser {
accept(Token.LPAREN);
groupBy.setWithRollUp(true);
}
if (identifierEquals("CUBE")) {
lexer.nextToken();
accept(Token.LPAREN);
groupBy.setWithCube(true);
}
for (;;) {
SQLExpr item = parseGroupByItem();
@@ -297,7 +302,7 @@ public class SQLSelectParser extends SQLParser {
lexer.nextToken();
}
if (groupBy.isWithRollUp()) {
if (groupBy.isWithRollUp() || groupBy.isWithCube()) {
accept(Token.RPAREN);
}
@@ -1310,12 +1310,15 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
boolean oracle = JdbcConstants.ORACLE.equals(dbType);
boolean rollup = x.isWithRollUp();
boolean cube = x.isWithCube();
int itemSize = x.getItems().size();
if (itemSize > 0) {
print0(ucase ? "GROUP BY " : "group by ");
if (oracle && rollup) {
print0(ucase ? "ROLLUP (" : "rollup (");
} else if (oracle && cube) {
print0(ucase ? "CUBE (" : "cube (");
}
incrementIndent();
for (int i = 0; i < itemSize; ++i) {
@@ -1344,7 +1347,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
print0(ucase ? " WITH ROLLUP" : " with rollup");
}
if (x.isWithCube()) {
if (x.isWithCube() && !oracle) {
print0(ucase ? " WITH CUBE" : " with cube");
}