Search in sources :

Example 11 with Identifier

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);
    }
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) Expression(com.alibaba.cobar.parser.ast.expression.Expression) IndexColumnName(com.alibaba.cobar.parser.ast.fragment.ddl.index.IndexColumnName)

Example 12 with Identifier

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);
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) DDLTruncateStatement(com.alibaba.cobar.parser.ast.stmt.ddl.DDLTruncateStatement)

Example 13 with Identifier

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");
    }
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) Expression(com.alibaba.cobar.parser.ast.expression.Expression) DMLCallStatement(com.alibaba.cobar.parser.ast.stmt.dml.DMLCallStatement)

Example 14 with Identifier

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;
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) Wildcard(com.alibaba.cobar.parser.ast.expression.primary.Wildcard)

Example 15 with Identifier

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());
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier)

Aggregations

Identifier (com.alibaba.cobar.parser.ast.expression.primary.Identifier)50 Expression (com.alibaba.cobar.parser.ast.expression.Expression)28 QueryExpression (com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)18 RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)18 InExpression (com.alibaba.cobar.parser.ast.expression.comparison.InExpression)14 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)13 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)13 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)13 ComparisionNullSafeEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression)13 LogicalAndExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression)13 LogicalOrExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression)13 UserExpression (com.alibaba.cobar.parser.ast.expression.misc.UserExpression)13 CaseWhenOperatorExpression (com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression)13 MatchExpression (com.alibaba.cobar.parser.ast.expression.primary.MatchExpression)13 FunctionExpression (com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression)13 LikeExpression (com.alibaba.cobar.parser.ast.expression.string.LikeExpression)13 CollateExpression (com.alibaba.cobar.parser.ast.expression.type.CollateExpression)13 Pair (com.alibaba.cobar.parser.util.Pair)12 BinaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression)11 PolyadicOperatorExpression (com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression)11