use of com.alibaba.cobar.parser.ast.stmt.extension.ExtDDLDropPolicy in project cobar by alibaba.
the class MySQLDDLParser method ddlStmt.
/**
* nothing has been pre-consumed
*/
public DDLStatement ddlStmt() throws SQLSyntaxErrorException {
Identifier idTemp1;
Identifier idTemp2;
SpecialIdentifier siTemp;
switch(lexer.token()) {
case KW_ALTER:
boolean ignore = false;
if (lexer.nextToken() == KW_IGNORE) {
ignore = true;
lexer.nextToken();
}
switch(lexer.token()) {
case KW_TABLE:
lexer.nextToken();
idTemp1 = identifier();
DDLAlterTableStatement alterTableStatement = new DDLAlterTableStatement(ignore, idTemp1);
return alterTable(alterTableStatement);
default:
throw err("Only ALTER TABLE is supported");
}
case KW_CREATE:
switch(lexer.nextToken()) {
case KW_UNIQUE:
case KW_FULLTEXT:
case KW_SPATIAL:
lexer.nextToken();
case KW_INDEX:
lexer.nextToken();
idTemp1 = identifier();
for (; lexer.token() != KW_ON; lexer.nextToken()) ;
lexer.nextToken();
idTemp2 = identifier();
return new DDLCreateIndexStatement(idTemp1, idTemp2);
case KW_TABLE:
lexer.nextToken();
return createTable(false);
case IDENTIFIER:
siTemp = specialIdentifiers.get(lexer.stringValueUppercase());
if (siTemp != null) {
switch(siTemp) {
case TEMPORARY:
lexer.nextToken();
match(KW_TABLE);
return createTable(true);
case POLICY:
lexer.nextToken();
Identifier policyName = identifier();
match(PUNC_LEFT_PAREN);
ExtDDLCreatePolicy policy = new ExtDDLCreatePolicy(policyName);
for (int j = 0; lexer.token() != PUNC_RIGHT_PAREN; ++j) {
if (j > 0) {
match(PUNC_COMMA);
}
Integer id = lexer.integerValue().intValue();
match(LITERAL_NUM_PURE_DIGIT);
Expression val = exprParser.expression();
policy.addProportion(id, val);
}
match(PUNC_RIGHT_PAREN);
return policy;
}
}
default:
throw err("unsupported DDL for CREATE");
}
case KW_DROP:
switch(lexer.nextToken()) {
case KW_INDEX:
lexer.nextToken();
idTemp1 = identifier();
match(KW_ON);
idTemp2 = identifier();
return new DDLDropIndexStatement(idTemp1, idTemp2);
case KW_TABLE:
lexer.nextToken();
return dropTable(false);
case IDENTIFIER:
siTemp = specialIdentifiers.get(lexer.stringValueUppercase());
if (siTemp != null) {
switch(siTemp) {
case TEMPORARY:
lexer.nextToken();
match(KW_TABLE);
return dropTable(true);
case POLICY:
lexer.nextToken();
Identifier policyName = identifier();
return new ExtDDLDropPolicy(policyName);
}
}
default:
throw err("unsupported DDL for DROP");
}
case KW_RENAME:
lexer.nextToken();
match(KW_TABLE);
idTemp1 = identifier();
match(KW_TO);
idTemp2 = identifier();
List<Pair<Identifier, Identifier>> list;
if (lexer.token() != PUNC_COMMA) {
list = new ArrayList<Pair<Identifier, Identifier>>(1);
list.add(new Pair<Identifier, Identifier>(idTemp1, idTemp2));
return new DDLRenameTableStatement(list);
}
list = new LinkedList<Pair<Identifier, Identifier>>();
list.add(new Pair<Identifier, Identifier>(idTemp1, idTemp2));
for (; lexer.token() == PUNC_COMMA; ) {
lexer.nextToken();
idTemp1 = identifier();
match(KW_TO);
idTemp2 = identifier();
list.add(new Pair<Identifier, Identifier>(idTemp1, idTemp2));
}
return new DDLRenameTableStatement(list);
case IDENTIFIER:
SpecialIdentifier si = specialIdentifiers.get(lexer.stringValueUppercase());
if (si != null) {
switch(si) {
case TRUNCATE:
return truncate();
}
}
default:
throw err("unsupported DDL");
}
}
Aggregations