use of com.alibaba.druid.sql.ast.SQLSubPartitionBy 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);
}
}
}
use of com.alibaba.druid.sql.ast.SQLSubPartitionBy in project druid by alibaba.
the class OracleCreateTableParser method parsePartitionByRest.
protected void parsePartitionByRest(SQLPartitionBy clause) {
if (lexer.token() == Token.STORE) {
lexer.nextToken();
accept(Token.IN);
accept(Token.LPAREN);
for (; ; ) {
SQLName tablespace = this.exprParser.name();
clause.getStoreIn().add(tablespace);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
}
if (identifierEquals("SUBPARTITION")) {
SQLSubPartitionBy subPartitionBy = subPartitionBy();
clause.setSubPartitionBy(subPartitionBy);
}
accept(Token.LPAREN);
for (; ; ) {
SQLPartition partition = parsePartition();
clause.addPartition(partition);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
}
use of com.alibaba.druid.sql.ast.SQLSubPartitionBy in project druid by alibaba.
the class MySqlOutputVisitor method visit.
public boolean visit(SQLVariantRefExpr x) {
{
int parametersSize = this.getParametersSize();
int index = x.getIndex();
if (index >= 0 && index < parametersSize) {
return super.visit(x);
}
}
String varName = x.getName();
if (x.isGlobal()) {
print0("@@global.");
} else {
if (// /
(!varName.startsWith("@")) && //
(!varName.equals("?")) && //
(!varName.startsWith("#")) && //
(!varName.startsWith("$")) && (!varName.startsWith(":"))) {
boolean subPartitionOption = false;
if (x.getParent() != null) {
subPartitionOption = x.getParent().getParent() instanceof SQLSubPartitionBy;
}
if (!subPartitionOption) {
print0("@@");
}
}
}
for (int i = 0; i < x.getName().length(); ++i) {
char ch = x.getName().charAt(i);
if (ch == '\'') {
if (x.getName().startsWith("@@") && i == 2) {
print(ch);
} else if (x.getName().startsWith("@") && i == 1) {
print(ch);
} else if (i != 0 && i != x.getName().length() - 1) {
print0("\\'");
} else {
print(ch);
}
} else {
print(ch);
}
}
String collate = (String) x.getAttribute("COLLATE");
if (collate != null) {
print0(ucase ? " COLLATE " : " collate ");
print0(collate);
}
return false;
}
Aggregations