use of com.alibaba.cobar.parser.ast.stmt.ddl.DDLCreateTableStatement in project cobar by alibaba.
the class MySQLDDLParser method createTable.
/**
* <code>TABLE</code> has been consumed
*/
private DDLCreateTableStatement createTable(boolean temp) throws SQLSyntaxErrorException {
boolean ifNotExists = false;
if (lexer.token() == KW_IF) {
lexer.nextToken();
match(KW_NOT);
match(KW_EXISTS);
ifNotExists = true;
}
Identifier table = identifier();
DDLCreateTableStatement stmt = new DDLCreateTableStatement(temp, ifNotExists, table);
createTableDefs(stmt);
TableOptions options = new TableOptions();
stmt.setTableOptions(options);
tableOptions(options);
DDLCreateTableStatement.SelectOption selectOpt = null;
switch(lexer.token()) {
case KW_IGNORE:
selectOpt = DDLCreateTableStatement.SelectOption.IGNORED;
if (lexer.nextToken() == KW_AS) {
lexer.nextToken();
}
break;
case KW_REPLACE:
selectOpt = DDLCreateTableStatement.SelectOption.REPLACE;
if (lexer.nextToken() == KW_AS) {
lexer.nextToken();
}
break;
case KW_AS:
lexer.nextToken();
case KW_SELECT:
break;
case EOF:
return stmt;
default:
throw new SQLSyntaxErrorException("DDL CREATE TABLE statement not end properly");
}
DMLSelectStatement select = new MySQLDMLSelectParser(lexer, exprParser).select();
stmt.setSelect(selectOpt, select);
match(EOF);
return stmt;
}
Aggregations