use of com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByList in project druid by alibaba.
the class MySqlCreateTableParser method partitionClauseRest.
protected void partitionClauseRest(SQLPartitionBy clause) {
if (identifierEquals("PARTITIONS")) {
lexer.nextToken();
SQLIntegerExpr countExpr = this.exprParser.integerExpr();
clause.setPartitionsCount(countExpr);
}
if (lexer.token() == Token.PARTITION) {
lexer.nextToken();
if (identifierEquals("NUM")) {
lexer.nextToken();
}
clause.setPartitionsCount(this.exprParser.expr());
clause.putAttribute("ads.partition", Boolean.TRUE);
}
if (identifierEquals("SUBPARTITION")) {
lexer.nextToken();
accept(Token.BY);
SQLSubPartitionBy subPartitionByClause = null;
boolean linear = false;
if (identifierEquals("LINEAR")) {
lexer.nextToken();
linear = true;
}
if (lexer.token() == Token.KEY) {
MySqlSubPartitionByKey subPartitionKey = new MySqlSubPartitionByKey();
lexer.nextToken();
if (linear) {
clause.setLinear(true);
}
accept(Token.LPAREN);
for (; ; ) {
subPartitionKey.addColumn(this.exprParser.name());
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
subPartitionByClause = subPartitionKey;
} else if (identifierEquals("HASH")) {
lexer.nextToken();
SQLSubPartitionByHash subPartitionHash = new SQLSubPartitionByHash();
if (linear) {
clause.setLinear(true);
}
if (lexer.token() == Token.KEY) {
lexer.nextToken();
subPartitionHash.setKey(true);
}
accept(Token.LPAREN);
subPartitionHash.setExpr(this.exprParser.expr());
accept(Token.RPAREN);
subPartitionByClause = subPartitionHash;
} else if (identifierEquals("LIST")) {
lexer.nextToken();
MySqlSubPartitionByList subPartitionList = new MySqlSubPartitionByList();
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
SQLExpr expr = this.exprParser.expr();
if (expr instanceof SQLIdentifierExpr && (identifierEquals("bigint") || identifierEquals("long"))) {
String dataType = lexer.stringVal();
lexer.nextToken();
SQLColumnDefinition column = this.exprParser.createColumnDefinition();
column.setName((SQLIdentifierExpr) expr);
column.setDataType(new SQLDataTypeImpl(dataType));
subPartitionList.addColumn(column);
subPartitionList.putAttribute("ads.subPartitionList", Boolean.TRUE);
} else {
subPartitionList.setExpr(expr);
}
accept(Token.RPAREN);
} else {
acceptIdentifier("COLUMNS");
accept(Token.LPAREN);
for (; ; ) {
subPartitionList.addColumn(this.exprParser.parseColumn());
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
}
subPartitionByClause = subPartitionList;
}
if (identifierEquals("SUBPARTITION")) {
lexer.nextToken();
acceptIdentifier("OPTIONS");
accept(Token.LPAREN);
SQLAssignItem option = this.exprParser.parseAssignItem();
accept(Token.RPAREN);
option.setParent(subPartitionByClause);
subPartitionByClause.getOptions().add(option);
}
if (identifierEquals("SUBPARTITIONS")) {
lexer.nextToken();
Number intValue = lexer.integerValue();
SQLNumberExpr numExpr = new SQLNumberExpr(intValue);
subPartitionByClause.setSubPartitionsCount(numExpr);
lexer.nextToken();
}
if (subPartitionByClause != null) {
subPartitionByClause.setLinear(linear);
clause.setSubPartitionBy(subPartitionByClause);
}
}
}
Aggregations