Skip to content

Commit

Permalink
improve mysql createTable parser
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Sep 14, 2014
1 parent 05a9b50 commit 01760a2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyConstraint;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.ast.statement.SQLTableConstraint;
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
Expand Down Expand Up @@ -338,6 +339,29 @@ public MySqlCreateTableStatement parseCrateTable(boolean acceptCreate) {
stmt.getTableOptions().put("STATS_PERSISTENT", this.exprParser.expr());
continue;
}

if (identifierEquals("STATS_SAMPLE_PAGES")) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}

stmt.getTableOptions().put("STATS_SAMPLE_PAGES", this.exprParser.expr());
continue;
}

if (lexer.token() == Token.UNION) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}

accept(Token.LPAREN);
SQLTableSource tableSrc = this.createSQLSelectParser().parseTableSource();
stmt.getTableOptions().put("UNION", tableSrc);
accept(Token.RPAREN);
continue;
}

if (lexer.token() == Token.TABLESPACE) {
lexer.nextToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ public boolean visit(MySqlCreateTableStatement x) {
print(' ');
option.getValue().accept(this);
continue;
} else if ("UNION".equals(key)) {
print(" = (");
option.getValue().accept(this);
print(')');
continue;
}

print(" = ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint;
Expand Down Expand Up @@ -1156,7 +1157,15 @@ public void endVisit(MySqlAlterTableOption x) {

@Override
public boolean visit(MySqlCreateTableStatement x) {
return super.visit((SQLCreateTableStatement) x);
boolean val = super.visit((SQLCreateTableStatement) x);

for (SQLObject option : x.getTableOptions().values()) {
if (option instanceof SQLTableSource) {
option.accept(this);
}
}

return val;
}

@Override
Expand Down Expand Up @@ -1341,7 +1350,7 @@ public boolean visit(MySqlHintStatement x) {

@Override
public void endVisit(MySqlHintStatement x) {

}

}

0 comments on commit 01760a2

Please sign in to comment.