Search in sources :

Example 1 with IndexOption

use of com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexOption in project cobar by alibaba.

the class MySQLDDLParser method indexDefinition.

// col_name column_definition
// | [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...)
// [index_option] ...
// | {INDEX|KEY} [index_name] [index_type] (index_col_name,...)
// [index_option] ...
// | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY] [index_name] [index_type]
// (index_col_name,...) [index_option] ...
// | {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (index_col_name,...)
// [index_option] ...
// | [CONSTRAINT [symbol]] FOREIGN KEY [index_name] (index_col_name,...)
// reference_definition
// | CHECK (expr)
private IndexDefinition indexDefinition() throws SQLSyntaxErrorException {
    IndexDefinition.IndexType indexType = null;
    List<IndexColumnName> columns = new ArrayList<IndexColumnName>(1);
    if (lexer.token() == KW_USING) {
        lexer.nextToken();
        int tp = matchIdentifier("BTREE", "HASH");
        indexType = tp == 0 ? IndexDefinition.IndexType.BTREE : IndexDefinition.IndexType.HASH;
    }
    match(PUNC_LEFT_PAREN);
    for (int i = 0; lexer.token() != PUNC_RIGHT_PAREN; ++i) {
        if (i > 0)
            match(PUNC_COMMA);
        IndexColumnName indexColumnName = indexColumnName();
        columns.add(indexColumnName);
    }
    match(PUNC_RIGHT_PAREN);
    List<IndexOption> options = indexOptions();
    return new IndexDefinition(indexType, columns, options);
}
Also used : IndexDefinition(com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexDefinition) IndexColumnName(com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexColumnName) IndexOption(com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexOption) ArrayList(java.util.ArrayList)

Aggregations

IndexColumnName (com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexColumnName)1 IndexDefinition (com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexDefinition)1 IndexOption (com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexOption)1 ArrayList (java.util.ArrayList)1