mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve mysql ddl parser
This commit is contained in:
+11
-2
@@ -31,6 +31,8 @@ public class MySqlPartitionByHash extends MySqlObjectImpl implements SQLPartitio
|
||||
|
||||
private SQLExpr partitionCount;
|
||||
|
||||
private boolean linear;
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -48,13 +50,20 @@ public class MySqlPartitionByHash extends MySqlObjectImpl implements SQLPartitio
|
||||
this.partitionCount = partitionCount;
|
||||
}
|
||||
|
||||
|
||||
public SQLExpr getExpr() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
||||
public void setExpr(SQLExpr expr) {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public boolean isLinear() {
|
||||
return linear;
|
||||
}
|
||||
|
||||
public void setLinear(boolean linear) {
|
||||
this.linear = linear;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
@@ -32,6 +32,8 @@ public class MySqlPartitionByKey extends MySqlObjectImpl implements SQLPartition
|
||||
|
||||
private SQLExpr partitionCount;
|
||||
|
||||
private boolean linear;
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -57,4 +59,12 @@ public class MySqlPartitionByKey extends MySqlObjectImpl implements SQLPartition
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public boolean isLinear() {
|
||||
return linear;
|
||||
}
|
||||
|
||||
public void setLinear(boolean linear) {
|
||||
this.linear = linear;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -355,10 +355,21 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (identifierEquals("PARTITION")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
|
||||
boolean linera = false;
|
||||
if (identifierEquals("LINEAR")) {
|
||||
lexer.nextToken();
|
||||
linera = true;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.KEY) {
|
||||
MySqlPartitionByKey clause = new MySqlPartitionByKey();
|
||||
lexer.nextToken();
|
||||
|
||||
if (linera) {
|
||||
clause.setLinear(true);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
for (;;) {
|
||||
clause.getColumns().add(this.exprParser.name());
|
||||
@@ -379,6 +390,10 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
MySqlPartitionByHash clause = new MySqlPartitionByHash();
|
||||
|
||||
if (linera) {
|
||||
clause.setLinear(true);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
clause.setExpr(this.exprParser.expr());
|
||||
accept(Token.RPAREN);
|
||||
|
||||
@@ -1496,7 +1496,11 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlPartitionByKey x) {
|
||||
print("PARTITION BY KEY (");
|
||||
if (x.isLinear()) {
|
||||
print("PARTITION BY LINEAR KEY (");
|
||||
} else {
|
||||
print("PARTITION BY KEY (");
|
||||
}
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(")");
|
||||
|
||||
@@ -1514,7 +1518,12 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlPartitionByHash x) {
|
||||
print("PARTITION BY HASH (");
|
||||
if (x.isLinear()) {
|
||||
print("PARTITION BY LINEAR HASH (");
|
||||
} else {
|
||||
print("PARTITION BY HASH (");
|
||||
}
|
||||
//
|
||||
x.getExpr().accept(this);
|
||||
print(")");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user