in core/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlCreateTableParser.java [627:1029]
protected void parseOptions(MySqlCreateTableStatement stmt) {
for (; ; ) {
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
}
if (lexer.identifierEquals(FnvHash.Constants.ENGINE)) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
SQLExpr expr = null;
if (lexer.token() == Token.MERGE) {
expr = new SQLIdentifierExpr(lexer.stringVal());
lexer.nextToken();
} else {
expr = this.exprParser.expr();
}
stmt.setEngine(expr);
continue;
}
if (parseOption(stmt)) {
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.BLOCK_SIZE)) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
SQLExpr expr = null;
if (lexer.token() == Token.MERGE) {
expr = new SQLIdentifierExpr(lexer.stringVal());
lexer.nextToken();
} else {
expr = this.exprParser.integerExpr();
}
stmt.addOption("BLOCK_SIZE", expr);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.PCTFREE)) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
SQLExpr expr = this.exprParser.integerExpr();
stmt.addOption("PCTFREE", expr);
continue;
}
if (lexer.token() == Token.DEFAULT) {
lexer.nextToken();
parseTableOptionCharsetOrCollate(stmt);
continue;
}
if (parseTableOptionCharsetOrCollate(stmt)) {
continue;
}
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
stmt.setComment(this.exprParser.expr());
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.DATA)) {
lexer.nextToken();
acceptIdentifier("DIRECTORY");
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
stmt.addOption("DATA DIRECTORY", this.exprParser.expr());
continue;
}
if (lexer.token() == Token.INDEX) {
lexer.nextToken();
acceptIdentifier("DIRECTORY");
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
stmt.addOption("INDEX DIRECTORY", this.exprParser.expr());
continue;
}
if (lexer.token() == Token.UNION) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
accept(Token.LPAREN);
SQLListExpr list = new SQLListExpr();
this.exprParser.exprList(list.getItems(), list);
stmt.addOption("UNION", list);
accept(Token.RPAREN);
continue;
}
if (lexer.token() == Token.TABLESPACE) {
lexer.nextToken();
TableSpaceOption option = new TableSpaceOption();
option.setName(this.exprParser.name());
if (lexer.identifierEquals("STORAGE")) {
lexer.nextToken();
option.setStorage(this.exprParser.name());
}
stmt.addOption("TABLESPACE", option);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.TABLEGROUP)) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
SQLName tableGroup = this.exprParser.name();
stmt.setTableGroup(tableGroup);
continue;
}
if (lexer.identifierEquals("INDEX_ALL")) {
lexer.nextToken();
accept(Token.EQ);
if (lexer.token() == Token.LITERAL_CHARS) {
if ("Y".equalsIgnoreCase(lexer.stringVal())) {
lexer.nextToken();
stmt.addOption("INDEX_ALL", new SQLCharExpr("Y"));
} else if ("N".equalsIgnoreCase(lexer.stringVal())) {
lexer.nextToken();
stmt.addOption("INDEX_ALL", new SQLCharExpr("N"));
} else {
throw new ParserException("INDEX_ALL accept parameter ['Y' or 'N'] only.");
}
}
continue;
}
if (lexer.identifierEquals("RT_INDEX_ALL")) {
lexer.nextToken();
accept(Token.EQ);
if (lexer.token() == Token.LITERAL_CHARS) {
if ("Y".equalsIgnoreCase(lexer.stringVal())) {
lexer.nextToken();
stmt.addOption("RT_INDEX_ALL", new SQLCharExpr("Y"));
} else if ("N".equalsIgnoreCase(lexer.stringVal())) {
lexer.nextToken();
stmt.addOption("RT_INDEX_ALL", new SQLCharExpr("N"));
} else {
throw new ParserException("RT_INDEX_ALL accepts parameter ['Y' or 'N'] only.");
}
}
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.ARCHIVE)) {
lexer.nextToken();
accept(Token.BY);
acceptIdentifier("OSS");
stmt.setArchiveBy(new SQLIdentifierExpr("OSS"));
continue;
}
if (lexer.identifierEquals("HOT_PARTITION_COUNT")) {
lexer.nextToken();
accept(Token.EQ);
try {
stmt.addOption("HOT_PARTITION_COUNT", this.exprParser.integerExpr());
} catch (Exception e) {
throw new ParserException("only integer number is supported for hot_partition_count");
}
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.CLUSTERED)) {
lexer.nextToken();
accept(Token.BY);
accept(Token.LPAREN);
for (; ; ) {
SQLSelectOrderByItem item = this.exprParser.parseSelectOrderByItem();
stmt.addClusteredByItem(item);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
continue;
}
if (lexer.token() == Token.PARTITION) {
SQLPartitionBy partitionClause = parsePartitionBy();
stmt.setPartitionBy(partitionClause);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.LOCAL)) {
SQLPartitionBy localPartitionClause = parseLocalPartitionBy();
stmt.setLocalPartitioning(localPartitionClause);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.BROADCAST)) {
lexer.nextToken();
stmt.setBroadCast(true);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.DISTRIBUTE) || lexer.identifierEquals(FnvHash.Constants.DISTRIBUTED)) {
lexer.nextToken();
accept(Token.BY);
if (lexer.identifierEquals(FnvHash.Constants.HASH)) {
lexer.nextToken();
accept(Token.LPAREN);
for (; ; ) {
SQLName name = this.exprParser.name();
stmt.getDistributeBy().add(name);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
stmt.setDistributeByType(new SQLIdentifierExpr("HASH"));
} else if (lexer.identifierEquals(FnvHash.Constants.DUPLICATE)) {
lexer.nextToken();
accept(Token.LPAREN);
for (; ; ) {
SQLName name = this.exprParser.name();
stmt.getDistributeBy().add(name);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
stmt.setDistributeByType(new SQLIdentifierExpr("DUPLICATE"));
} else if (lexer.identifierEquals(FnvHash.Constants.BROADCAST)) {
lexer.nextToken();
stmt.setDistributeByType(new SQLIdentifierExpr("BROADCAST"));
}
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.DBPARTITION)) {
lexer.nextToken();
accept(Token.BY);
SQLExpr dbPartitoinBy = this.exprParser.primary();
stmt.setDbPartitionBy(dbPartitoinBy);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.DBPARTITIONS)) {
lexer.nextToken();
SQLExpr dbPartitions = this.exprParser.primary();
stmt.setDbPartitions(dbPartitions);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.TBPARTITION)) {
lexer.nextToken();
accept(Token.BY);
SQLExpr expr = this.exprParser.expr();
if (lexer.identifierEquals(FnvHash.Constants.STARTWITH)) {
lexer.nextToken();
SQLExpr start = this.exprParser.primary();
acceptIdentifier("ENDWITH");
SQLExpr end = this.exprParser.primary();
expr = new SQLBetweenExpr(expr, start, end);
}
stmt.setTablePartitionBy(expr);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.TBPARTITIONS)) {
lexer.nextToken();
SQLExpr tbPartitions = this.exprParser.primary();
stmt.setTablePartitions(tbPartitions);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.EXTPARTITION)) {
lexer.nextToken();
accept(Token.LPAREN);
MySqlExtPartition partitionDef = new MySqlExtPartition();
for (; ; ) {
MySqlExtPartition.Item item = new MySqlExtPartition.Item();
if (lexer.identifierEquals(FnvHash.Constants.DBPARTITION)) {
lexer.nextToken();
SQLName name = this.exprParser.name();
item.setDbPartition(name);
accept(Token.BY);
SQLExpr value = this.exprParser.primary();
item.setDbPartitionBy(value);
}
if (lexer.identifierEquals(FnvHash.Constants.TBPARTITION)) {
lexer.nextToken();
SQLName name = this.exprParser.name();
item.setTbPartition(name);
accept(Token.BY);
SQLExpr value = this.exprParser.primary();
item.setTbPartitionBy(value);
}
item.setParent(partitionDef);
partitionDef.getItems().add(item);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
} else {
break;
}
}
accept(Token.RPAREN);
stmt.setExPartition(partitionDef);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.OPTIONS)) {
lexer.nextToken();
accept(Token.LPAREN);
stmt.putAttribute("ads.options", Boolean.TRUE);
for (; ; ) {
String name = lexer.stringVal();
lexer.nextToken();
accept(Token.EQ);
SQLExpr value = this.exprParser.primary();
stmt.addOption(name, value);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.STORED)) {
lexer.nextToken();
accept(Token.BY);
SQLName name = this.exprParser.name();
stmt.setStoredBy(name);
}
if (lexer.token() == Token.WITH) {
lexer.nextToken();
accept(Token.LPAREN);
for (; ; ) {
String name = lexer.stringVal();
lexer.nextToken();
accept(Token.EQ);
SQLName value = this.exprParser.name();
stmt.getWith().put(name, value);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
continue;
}
if (lexer.token() == (Token.HINT)) {
this.exprParser.parseHints(stmt.getOptionHints());
continue;
}
if (lexer.identifierEquals(FnvHash.Constants.SINGLE)) {
lexer.nextToken();
stmt.setSingle(true);
continue;
}
break;
}
}