Search in sources :

Example 1 with DDLCreateTableStatement

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;
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) TableOptions(com.alibaba.cobar.parser.ast.fragment.ddl.TableOptions) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) DMLSelectStatement(com.alibaba.cobar.parser.ast.stmt.dml.DMLSelectStatement) DDLCreateTableStatement(com.alibaba.cobar.parser.ast.stmt.ddl.DDLCreateTableStatement)

Aggregations

Identifier (com.alibaba.cobar.parser.ast.expression.primary.Identifier)1 TableOptions (com.alibaba.cobar.parser.ast.fragment.ddl.TableOptions)1 DDLCreateTableStatement (com.alibaba.cobar.parser.ast.stmt.ddl.DDLCreateTableStatement)1 DMLSelectStatement (com.alibaba.cobar.parser.ast.stmt.dml.DMLSelectStatement)1 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)1