use of com.alibaba.cobar.parser.ast.expression.primary.Identifier 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);
}
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class MySQLDDLParser method truncate.
public DDLTruncateStatement truncate() throws SQLSyntaxErrorException {
matchIdentifier("TRUNCATE");
if (lexer.token() == KW_TABLE) {
lexer.nextToken();
}
Identifier tb = identifier();
return new DDLTruncateStatement(tb);
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class MySQLDMLCallParser method call.
public DMLCallStatement call() throws SQLSyntaxErrorException {
match(KW_CALL);
Identifier procedure = identifier();
match(PUNC_LEFT_PAREN);
if (lexer.token() == PUNC_RIGHT_PAREN) {
lexer.nextToken();
return new DMLCallStatement(procedure);
}
List<Expression> arguments;
Expression expr = exprParser.expression();
switch(lexer.token()) {
case PUNC_COMMA:
arguments = new LinkedList<Expression>();
arguments.add(expr);
for (; lexer.token() == PUNC_COMMA; ) {
lexer.nextToken();
expr = exprParser.expression();
arguments.add(expr);
}
match(PUNC_RIGHT_PAREN);
return new DMLCallStatement(procedure, arguments);
case PUNC_RIGHT_PAREN:
lexer.nextToken();
arguments = new ArrayList<Expression>(1);
arguments.add(expr);
return new DMLCallStatement(procedure, arguments);
default:
throw err("expect ',' or ')' after first argument of procedure");
}
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class MySQLParser method identifier.
/**
* @return type of {@link Wildcard} is possible. never null
* @throws SQLSyntaxErrorException if identifier dose not matched
*/
public Identifier identifier() throws SQLSyntaxErrorException {
if (lexer.token() == null) {
lexer.nextToken();
}
Identifier id;
switch(lexer.token()) {
case OP_ASTERISK:
lexer.nextToken();
Wildcard wc = new Wildcard(null);
wc.setCacheEvalRst(cacheEvalRst);
return wc;
case IDENTIFIER:
id = new Identifier(null, lexer.stringValue(), lexer.stringValueUppercase());
id.setCacheEvalRst(cacheEvalRst);
lexer.nextToken();
break;
default:
throw err("expect id or * after '.'");
}
for (; lexer.token() == PUNC_DOT; ) {
switch(lexer.nextToken()) {
case OP_ASTERISK:
lexer.nextToken();
Wildcard wc = new Wildcard(id);
wc.setCacheEvalRst(cacheEvalRst);
return wc;
case IDENTIFIER:
id = new Identifier(id, lexer.stringValue(), lexer.stringValueUppercase());
id.setCacheEvalRst(cacheEvalRst);
lexer.nextToken();
break;
default:
throw err("expect id or * after '.'");
}
}
return id;
}
use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(ShowTables node) {
appendable.append("SHOW");
if (node.isFull())
appendable.append(" FULL");
appendable.append(" TABLES");
Identifier schema = node.getSchema();
if (schema != null) {
appendable.append(" FROM ");
schema.accept(this);
}
printLikeOrWhere(node.getPattern(), node.getWhere());
}
Aggregations