improved sql parser.

This commit is contained in:
wenshao
2017-10-10 10:31:50 +08:00
parent 141aca0cd3
commit cef99c1738
10 changed files with 269 additions and 19 deletions
@@ -170,6 +170,15 @@ public class DB2CreateTableParser extends SQLCreateTableParser {
lexer.nextToken();
SQLName validproc = this.exprParser.name();
createTable.setValidproc(validproc);
continue;
} else if (lexer.identifierEquals(FnvHash.Constants.COMPRESS)) {
lexer.nextToken();
createTable.setCompress(true);
if (lexer.identifierEquals(FnvHash.Constants.YES)) {
lexer.nextToken();
}
continue;
}
break;
}
@@ -118,6 +118,16 @@ public class DB2OutputVisitor extends SQLASTOutputVisitor implements DB2ASTVisit
partitionBy.accept(this);
}
Boolean compress = x.getCompress();
if (compress != null) {
println();
if (compress.booleanValue()) {
print0(ucase ? "COMPRESS YES" : "compress yes");
} else {
print0(ucase ? "COMPRESS NO" : "compress no");
}
}
return false;
}
@@ -116,10 +116,15 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
stmt.setSelect(query);
} else {
for (;;) {
SQLColumnDefinition column = null;
if (lexer.token() == Token.IDENTIFIER //
|| lexer.token() == Token.LITERAL_CHARS) {
SQLColumnDefinition column = this.exprParser.parseColumn();
column = this.exprParser.parseColumn();
stmt.getTableElementList().add(column);
if (lexer.isKeepComments() && lexer.hasComment()) {
column.addAfterComment(lexer.readAndResetComments());
}
} else if (lexer.token() == Token.CONSTRAINT //
|| lexer.token() == Token.PRIMARY //
|| lexer.token() == Token.UNIQUE) {
@@ -175,14 +180,17 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
SQLCheck check = this.exprParser.parseCheck();
stmt.getTableElementList().add(check);
} else {
SQLColumnDefinition column = this.exprParser.parseColumn();
column = this.exprParser.parseColumn();
stmt.getTableElementList().add(column);
}
if (!(lexer.token() == (Token.COMMA))) {
if (lexer.token() != Token.COMMA) {
break;
} else {
lexer.nextToken();
if (lexer.isKeepComments() && lexer.hasComment() && column != null) {
column.addAfterComment(lexer.readAndResetComments());
}
}
}
}
@@ -124,7 +124,7 @@ public class OdpsCreateTableParser extends SQLCreateTableParser {
column.addAfterComment(lexer.readAndResetComments());
}
if (!(lexer.token() == (Token.COMMA))) {
if (lexer.token() != Token.COMMA) {
break;
} else {
lexer.nextToken();
@@ -1523,7 +1523,7 @@ public class OracleExprParser extends SQLExprParser {
lexer.nextToken();
attributes.setCompress(Boolean.FALSE);
continue;
} else if (lexer.identifierEquals("COMPRESS")) {
} else if (lexer.identifierEquals(FnvHash.Constants.COMPRESS)) {
lexer.nextToken();
attributes.setCompress(Boolean.TRUE);
@@ -2428,21 +2428,33 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
protected void printTableElements(List<SQLTableElement> tableElementList) {
int size = tableElementList.size();
if (size > 0) {
print0(" (");
this.indentCount++;
println();
for (int i = 0; i < size; ++i) {
if (i != 0) {
print0(",");
println();
}
tableElementList.get(i).accept(this);
}
this.indentCount--;
println();
print(')');
if (size == 0) {
return;
}
print0(" (");
this.indentCount++;
println();
for (int i = 0; i < size; ++i) {
SQLTableElement element = tableElementList.get(i);
element.accept(this);
if (i != size - 1) {
print(',');
}
if (this.isPrettyFormat() && element.hasAfterComment()) {
print(' ');
printlnComment(element.getAfterCommentsDirect());
}
if (i != size - 1) {
println();
}
}
this.indentCount--;
println();
print(')');
}
public boolean visit(SQLCreateTableStatement x) {
@@ -513,5 +513,7 @@ public final class FnvHash {
long NONE = fnv1a_64_lower("NONE");
long PARTITIONING = fnv1a_64_lower("PARTITIONING");
long VALIDPROC = fnv1a_64_lower("VALIDPROC");
long COMPRESS = fnv1a_64_lower("COMPRESS");
long YES = fnv1a_64_lower("YES");
}
}