use of com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexColumnName 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);
}
use of com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexColumnName in project cobar by alibaba.
the class MySQLDDLParser method indexColumnName.
private IndexColumnName indexColumnName() throws SQLSyntaxErrorException {
// col_name [(length)] [ASC | DESC]
Identifier colName = identifier();
Expression len = null;
if (lexer.token() == PUNC_LEFT_PAREN) {
lexer.nextToken();
len = exprParser.expression();
match(PUNC_RIGHT_PAREN);
}
switch(lexer.token()) {
case KW_ASC:
lexer.nextToken();
return new IndexColumnName(colName, len, true);
case KW_DESC:
lexer.nextToken();
return new IndexColumnName(colName, len, false);
default:
return new IndexColumnName(colName, len, true);
}
}
Aggregations