Search in sources :

Example 1 with Identifier

use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.

the class MySQLDMLUpdateParser method update.

/**
     * nothing has been pre-consumed <code><pre>
     * 'UPDATE' 'LOW_PRIORITY'? 'IGNORE'? table_reference
     *   'SET' colName ('='|':=') (expr|'DEFAULT') (',' colName ('='|':=') (expr|'DEFAULT'))*
     *     ('WHERE' cond)?
     *     {singleTable}? => ('ORDER' 'BY' orderBy)?  ('LIMIT' count)?
     * </pre></code>
     */
public DMLUpdateStatement update() throws SQLSyntaxErrorException {
    match(KW_UPDATE);
    boolean lowPriority = false;
    boolean ignore = false;
    if (lexer.token() == KW_LOW_PRIORITY) {
        lexer.nextToken();
        lowPriority = true;
    }
    if (lexer.token() == KW_IGNORE) {
        lexer.nextToken();
        ignore = true;
    }
    TableReferences tableRefs = tableRefs();
    match(KW_SET);
    List<Pair<Identifier, Expression>> values;
    Identifier col = identifier();
    match(OP_EQUALS, OP_ASSIGN);
    Expression expr = exprParser.expression();
    if (lexer.token() == PUNC_COMMA) {
        values = new LinkedList<Pair<Identifier, Expression>>();
        values.add(new Pair<Identifier, Expression>(col, expr));
        for (; lexer.token() == PUNC_COMMA; ) {
            lexer.nextToken();
            col = identifier();
            match(OP_EQUALS, OP_ASSIGN);
            expr = exprParser.expression();
            values.add(new Pair<Identifier, Expression>(col, expr));
        }
    } else {
        values = new ArrayList<Pair<Identifier, Expression>>(1);
        values.add(new Pair<Identifier, Expression>(col, expr));
    }
    Expression where = null;
    if (lexer.token() == KW_WHERE) {
        lexer.nextToken();
        where = exprParser.expression();
    }
    OrderBy orderBy = null;
    Limit limit = null;
    if (tableRefs.isSingleTable()) {
        orderBy = orderBy();
        limit = limit();
    }
    return new DMLUpdateStatement(lowPriority, ignore, tableRefs, values, where, orderBy, limit);
}
Also used : OrderBy(com.alibaba.cobar.parser.ast.fragment.OrderBy) Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) Expression(com.alibaba.cobar.parser.ast.expression.Expression) DMLUpdateStatement(com.alibaba.cobar.parser.ast.stmt.dml.DMLUpdateStatement) Limit(com.alibaba.cobar.parser.ast.fragment.Limit) TableReferences(com.alibaba.cobar.parser.ast.fragment.tableref.TableReferences) Pair(com.alibaba.cobar.parser.util.Pair)

Example 2 with Identifier

use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.

the class MySQLExprParser method userExpression.

private Expression userExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
    Expression first = primaryExpression(consumed, consumedUp);
    if (lexer.token() == USR_VAR) {
        if (first instanceof LiteralString) {
            StringBuilder str = new StringBuilder().append('\'').append(((LiteralString) first).getString()).append('\'').append(lexer.stringValue());
            lexer.nextToken();
            return new UserExpression(str.toString()).setCacheEvalRst(cacheEvalRst);
        } else if (first instanceof Identifier) {
            StringBuilder str = new StringBuilder().append(((Identifier) first).getIdText()).append(lexer.stringValue());
            lexer.nextToken();
            return new UserExpression(str.toString()).setCacheEvalRst(cacheEvalRst);
        }
    }
    return first;
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString) SubqueryAllExpression(com.alibaba.cobar.parser.ast.expression.misc.SubqueryAllExpression) MinusExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.MinusExpression) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) BitAndExpression(com.alibaba.cobar.parser.ast.expression.bit.BitAndExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) NegativeValueExpression(com.alibaba.cobar.parser.ast.expression.logical.NegativeValueExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) CastBinaryExpression(com.alibaba.cobar.parser.ast.expression.type.CastBinaryExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) BitInvertExpression(com.alibaba.cobar.parser.ast.expression.bit.BitInvertExpression) BitXORExpression(com.alibaba.cobar.parser.ast.expression.bit.BitXORExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) BitShiftExpression(com.alibaba.cobar.parser.ast.expression.bit.BitShiftExpression) BitOrExpression(com.alibaba.cobar.parser.ast.expression.bit.BitOrExpression) ComparisionGreaterThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanOrEqualsExpression) MatchExpression(com.alibaba.cobar.parser.ast.expression.primary.MatchExpression) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) LogicalOrExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression) ComparisionGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanExpression) ComparisionLessOrGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessOrGreaterThanExpression) SubqueryAnyExpression(com.alibaba.cobar.parser.ast.expression.misc.SubqueryAnyExpression) RegexpExpression(com.alibaba.cobar.parser.ast.expression.string.RegexpExpression) LogicalAndExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression) ArithmeticMultiplyExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticMultiplyExpression) ComparisionLessThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanOrEqualsExpression) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) ArithmeticSubtractExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticSubtractExpression) SoundsLikeExpression(com.alibaba.cobar.parser.ast.expression.string.SoundsLikeExpression) ArithmeticIntegerDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticIntegerDivideExpression) CollateExpression(com.alibaba.cobar.parser.ast.expression.type.CollateExpression) LogicalNotExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalNotExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression) AssignmentExpression(com.alibaba.cobar.parser.ast.expression.misc.AssignmentExpression) CaseWhenOperatorExpression(com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression) LogicalXORExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalXORExpression) UserExpression(com.alibaba.cobar.parser.ast.expression.misc.UserExpression) ArithmeticAddExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticAddExpression) ComparisionNotEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNotEqualsExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) ComparisionLessThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanExpression) ArithmeticModExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticModExpression) ArithmeticDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticDivideExpression) UserExpression(com.alibaba.cobar.parser.ast.expression.misc.UserExpression)

Example 3 with Identifier

use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.

the class ServerRouter method validateAST.

private static void validateAST(SQLStatement ast, TableConfig tc, RuleConfig rule, PartitionKeyVisitor visitor) throws SQLNonTransientException {
    if (ast instanceof DMLUpdateStatement) {
        List<Identifier> columns = null;
        List<String> ruleCols = rule.getColumns();
        DMLUpdateStatement update = (DMLUpdateStatement) ast;
        for (Pair<Identifier, Expression> pair : update.getValues()) {
            for (String ruleCol : ruleCols) {
                if (equals(pair.getKey().getIdTextUpUnescape(), ruleCol)) {
                    if (columns == null) {
                        columns = new ArrayList<Identifier>(ruleCols.size());
                    }
                    columns.add(pair.getKey());
                }
            }
        }
        if (columns == null) {
            return;
        }
        Map<String, String> alias = visitor.getTableAlias();
        for (Identifier column : columns) {
            String table = column.getLevelUnescapeUpName(2);
            table = alias.get(table);
            if (table != null && table.equals(tc.getName())) {
                throw new SQLFeatureNotSupportedException("partition key cannot be changed");
            }
        }
    }
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) Expression(com.alibaba.cobar.parser.ast.expression.Expression) ReplacableExpression(com.alibaba.cobar.parser.ast.expression.ReplacableExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) DMLUpdateStatement(com.alibaba.cobar.parser.ast.stmt.dml.DMLUpdateStatement)

Example 4 with Identifier

use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.

the class MySQLDALParser method show.

public DALShowStatement show() throws SQLSyntaxErrorException {
    match(KW_SHOW);
    String tempStr;
    String tempStrUp;
    Expression tempExpr;
    Identifier tempId;
    SpecialIdentifier tempSi;
    Limit tempLimit;
    switch(lexer.token()) {
        case KW_BINARY:
            lexer.nextToken();
            matchIdentifier("LOGS");
            return new ShowBinaryLog();
        case KW_CHARACTER:
            lexer.nextToken();
            match(KW_SET);
            switch(lexer.token()) {
                case KW_LIKE:
                    tempStr = like();
                    return new ShowCharaterSet(tempStr);
                case KW_WHERE:
                    tempExpr = where();
                    return new ShowCharaterSet(tempExpr);
                default:
                    return new ShowCharaterSet();
            }
        case KW_CREATE:
            ShowCreate.Type showCreateType;
            switch1: switch(lexer.nextToken()) {
                case KW_DATABASE:
                    showCreateType = ShowCreate.Type.DATABASE;
                    break;
                case KW_PROCEDURE:
                    showCreateType = ShowCreate.Type.PROCEDURE;
                    break;
                case KW_TABLE:
                    showCreateType = ShowCreate.Type.TABLE;
                    break;
                case KW_TRIGGER:
                    showCreateType = ShowCreate.Type.TRIGGER;
                    break;
                case IDENTIFIER:
                    tempSi = specialIdentifiers.get(lexer.stringValueUppercase());
                    if (tempSi != null) {
                        switch(tempSi) {
                            case EVENT:
                                showCreateType = ShowCreate.Type.EVENT;
                                break switch1;
                            case FUNCTION:
                                showCreateType = ShowCreate.Type.FUNCTION;
                                break switch1;
                            case VIEW:
                                showCreateType = ShowCreate.Type.VIEW;
                                break switch1;
                        }
                    }
                default:
                    throw err("unexpect token for SHOW CREATE");
            }
            lexer.nextToken();
            tempId = identifier();
            return new ShowCreate(showCreateType, tempId);
        case KW_SCHEMAS:
        case KW_DATABASES:
            lexer.nextToken();
            switch(lexer.token()) {
                case KW_LIKE:
                    tempStr = like();
                    return new ShowDatabases(tempStr);
                case KW_WHERE:
                    tempExpr = where();
                    return new ShowDatabases(tempExpr);
            }
            return new ShowDatabases();
        case KW_KEYS:
            return showIndex(ShowIndex.Type.KEYS);
        case KW_INDEX:
            return showIndex(ShowIndex.Type.INDEX);
        case KW_PROCEDURE:
            lexer.nextToken();
            tempStrUp = lexer.stringValueUppercase();
            tempSi = specialIdentifiers.get(tempStrUp);
            if (tempSi != null) {
                switch(tempSi) {
                    case CODE:
                        lexer.nextToken();
                        tempId = identifier();
                        return new ShowProcedureCode(tempId);
                    case STATUS:
                        switch(lexer.nextToken()) {
                            case KW_LIKE:
                                tempStr = like();
                                return new ShowProcedureStatus(tempStr);
                            case KW_WHERE:
                                tempExpr = where();
                                return new ShowProcedureStatus(tempExpr);
                            default:
                                return new ShowProcedureStatus();
                        }
                }
            }
            throw err("unexpect token for SHOW PROCEDURE");
        case KW_TABLE:
            lexer.nextToken();
            matchIdentifier("STATUS");
            tempId = null;
            if (lexer.token() == KW_FROM || lexer.token() == KW_IN) {
                lexer.nextToken();
                tempId = identifier();
            }
            switch(lexer.token()) {
                case KW_LIKE:
                    tempStr = like();
                    return new ShowTableStatus(tempId, tempStr);
                case KW_WHERE:
                    tempExpr = where();
                    return new ShowTableStatus(tempId, tempExpr);
            }
            return new ShowTableStatus(tempId);
        case IDENTIFIER:
            tempStrUp = lexer.stringValueUppercase();
            tempSi = specialIdentifiers.get(tempStrUp);
            if (tempSi == null) {
                break;
            }
            switch(tempSi) {
                case INDEXES:
                    return showIndex(ShowIndex.Type.INDEXES);
                case GRANTS:
                    if (lexer.nextToken() == KW_FOR) {
                        lexer.nextToken();
                        tempExpr = exprParser.expression();
                        return new ShowGrants(tempExpr);
                    }
                    return new ShowGrants();
                case AUTHORS:
                    lexer.nextToken();
                    return new ShowAuthors();
                case BINLOG:
                    lexer.nextToken();
                    matchIdentifier("EVENTS");
                    tempStr = null;
                    tempExpr = null;
                    tempLimit = null;
                    if (lexer.token() == KW_IN) {
                        lexer.nextToken();
                        tempStr = lexer.stringValue();
                        lexer.nextToken();
                    }
                    if (lexer.token() == KW_FROM) {
                        lexer.nextToken();
                        tempExpr = exprParser.expression();
                    }
                    if (lexer.token() == KW_LIMIT) {
                        tempLimit = limit();
                    }
                    return new ShowBinLogEvent(tempStr, tempExpr, tempLimit);
                case COLLATION:
                    switch(lexer.nextToken()) {
                        case KW_LIKE:
                            tempStr = like();
                            return new ShowCollation(tempStr);
                        case KW_WHERE:
                            tempExpr = where();
                            return new ShowCollation(tempExpr);
                    }
                    return new ShowCollation();
                case COLUMNS:
                    return showColumns(false);
                case CONTRIBUTORS:
                    lexer.nextToken();
                    return new ShowContributors();
                case ENGINE:
                    switch(lexer.nextToken()) {
                        case IDENTIFIER:
                            tempStrUp = lexer.stringValueUppercase();
                            tempSi = specialIdentifiers.get(tempStrUp);
                            if (tempSi != null) {
                                switch(tempSi) {
                                    case INNODB:
                                        lexer.nextToken();
                                        tempStrUp = lexer.stringValueUppercase();
                                        tempSi = specialIdentifiers.get(tempStrUp);
                                        if (tempSi != null) {
                                            switch(tempSi) {
                                                case STATUS:
                                                    lexer.nextToken();
                                                    return new ShowEngine(ShowEngine.Type.INNODB_STATUS);
                                                case MUTEX:
                                                    lexer.nextToken();
                                                    return new ShowEngine(ShowEngine.Type.INNODB_MUTEX);
                                            }
                                        }
                                    case PERFORMANCE_SCHEMA:
                                        lexer.nextToken();
                                        matchIdentifier("STATUS");
                                        return new ShowEngine(ShowEngine.Type.PERFORMANCE_SCHEMA_STATUS);
                                }
                            }
                        default:
                            throw err("unexpect token for SHOW ENGINE");
                    }
                case ENGINES:
                    lexer.nextToken();
                    return new ShowEngines();
                case ERRORS:
                    lexer.nextToken();
                    tempLimit = limit();
                    return new ShowErrors(false, tempLimit);
                case COUNT:
                    lexer.nextToken();
                    match(PUNC_LEFT_PAREN);
                    match(OP_ASTERISK);
                    match(PUNC_RIGHT_PAREN);
                    switch(matchIdentifier("ERRORS", "WARNINGS")) {
                        case 0:
                            return new ShowErrors(true, null);
                        case 1:
                            return new ShowWarnings(true, null);
                    }
                case EVENTS:
                    tempId = null;
                    switch(lexer.nextToken()) {
                        case KW_IN:
                        case KW_FROM:
                            lexer.nextToken();
                            tempId = identifier();
                    }
                    switch(lexer.token()) {
                        case KW_LIKE:
                            tempStr = like();
                            return new ShowEvents(tempId, tempStr);
                        case KW_WHERE:
                            tempExpr = where();
                            return new ShowEvents(tempId, tempExpr);
                        default:
                            return new ShowEvents(tempId);
                    }
                case FULL:
                    lexer.nextToken();
                    tempStrUp = lexer.stringValueUppercase();
                    tempSi = specialIdentifiers.get(tempStrUp);
                    if (tempSi != null) {
                        switch(tempSi) {
                            case COLUMNS:
                                return showColumns(true);
                            case PROCESSLIST:
                                lexer.nextToken();
                                return new ShowProcesslist(true);
                            case TABLES:
                                tempId = null;
                                switch(lexer.nextToken()) {
                                    case KW_IN:
                                    case KW_FROM:
                                        lexer.nextToken();
                                        tempId = identifier();
                                }
                                switch(lexer.token()) {
                                    case KW_LIKE:
                                        tempStr = like();
                                        return new ShowTables(true, tempId, tempStr);
                                    case KW_WHERE:
                                        tempExpr = where();
                                        return new ShowTables(true, tempId, tempExpr);
                                    default:
                                        return new ShowTables(true, tempId);
                                }
                        }
                    }
                    throw err("unexpected token for SHOW FULL");
                case FUNCTION:
                    lexer.nextToken();
                    tempStrUp = lexer.stringValueUppercase();
                    tempSi = specialIdentifiers.get(tempStrUp);
                    if (tempSi != null) {
                        switch(tempSi) {
                            case CODE:
                                lexer.nextToken();
                                tempId = identifier();
                                return new ShowFunctionCode(tempId);
                            case STATUS:
                                switch(lexer.nextToken()) {
                                    case KW_LIKE:
                                        tempStr = like();
                                        return new ShowFunctionStatus(tempStr);
                                    case KW_WHERE:
                                        tempExpr = where();
                                        return new ShowFunctionStatus(tempExpr);
                                    default:
                                        return new ShowFunctionStatus();
                                }
                        }
                    }
                    throw err("unexpected token for SHOW FUNCTION");
                case GLOBAL:
                    lexer.nextToken();
                    tempStrUp = lexer.stringValueUppercase();
                    tempSi = specialIdentifiers.get(tempStrUp);
                    if (tempSi != null) {
                        switch(tempSi) {
                            case STATUS:
                                switch(lexer.nextToken()) {
                                    case KW_LIKE:
                                        tempStr = like();
                                        return new ShowStatus(VariableScope.GLOBAL, tempStr);
                                    case KW_WHERE:
                                        tempExpr = where();
                                        return new ShowStatus(VariableScope.GLOBAL, tempExpr);
                                    default:
                                        return new ShowStatus(VariableScope.GLOBAL);
                                }
                            case VARIABLES:
                                switch(lexer.nextToken()) {
                                    case KW_LIKE:
                                        tempStr = like();
                                        return new ShowVariables(VariableScope.GLOBAL, tempStr);
                                    case KW_WHERE:
                                        tempExpr = where();
                                        return new ShowVariables(VariableScope.GLOBAL, tempExpr);
                                    default:
                                        return new ShowVariables(VariableScope.GLOBAL);
                                }
                        }
                    }
                    throw err("unexpected token for SHOW GLOBAL");
                case MASTER:
                    lexer.nextToken();
                    tempStrUp = lexer.stringValueUppercase();
                    tempSi = specialIdentifiers.get(tempStrUp);
                    if (tempSi != null && tempSi == SpecialIdentifier.STATUS) {
                        lexer.nextToken();
                        return new ShowMasterStatus();
                    }
                    matchIdentifier("LOGS");
                    return new ShowBinaryLog();
                case OPEN:
                    lexer.nextToken();
                    matchIdentifier("TABLES");
                    tempId = null;
                    switch(lexer.token()) {
                        case KW_IN:
                        case KW_FROM:
                            lexer.nextToken();
                            tempId = identifier();
                    }
                    switch(lexer.token()) {
                        case KW_LIKE:
                            tempStr = like();
                            return new ShowOpenTables(tempId, tempStr);
                        case KW_WHERE:
                            tempExpr = where();
                            return new ShowOpenTables(tempId, tempExpr);
                        default:
                            return new ShowOpenTables(tempId);
                    }
                case PLUGINS:
                    lexer.nextToken();
                    return new ShowPlugins();
                case PRIVILEGES:
                    lexer.nextToken();
                    return new ShowPrivileges();
                case PROCESSLIST:
                    lexer.nextToken();
                    return new ShowProcesslist(false);
                case PROFILE:
                    return showProfile();
                case PROFILES:
                    lexer.nextToken();
                    return new ShowProfiles();
                case LOCAL:
                case SESSION:
                    lexer.nextToken();
                    tempStrUp = lexer.stringValueUppercase();
                    tempSi = specialIdentifiers.get(tempStrUp);
                    if (tempSi != null) {
                        switch(tempSi) {
                            case STATUS:
                                switch(lexer.nextToken()) {
                                    case KW_LIKE:
                                        tempStr = like();
                                        return new ShowStatus(VariableScope.SESSION, tempStr);
                                    case KW_WHERE:
                                        tempExpr = where();
                                        return new ShowStatus(VariableScope.SESSION, tempExpr);
                                    default:
                                        return new ShowStatus(VariableScope.SESSION);
                                }
                            case VARIABLES:
                                switch(lexer.nextToken()) {
                                    case KW_LIKE:
                                        tempStr = like();
                                        return new ShowVariables(VariableScope.SESSION, tempStr);
                                    case KW_WHERE:
                                        tempExpr = where();
                                        return new ShowVariables(VariableScope.SESSION, tempExpr);
                                    default:
                                        return new ShowVariables(VariableScope.SESSION);
                                }
                        }
                    }
                    throw err("unexpected token for SHOW SESSION");
                case SLAVE:
                    lexer.nextToken();
                    tempStrUp = lexer.stringValueUppercase();
                    tempSi = specialIdentifiers.get(tempStrUp);
                    if (tempSi != null) {
                        switch(tempSi) {
                            case HOSTS:
                                lexer.nextToken();
                                return new ShowSlaveHosts();
                            case STATUS:
                                lexer.nextToken();
                                return new ShowSlaveStatus();
                        }
                    }
                    throw err("unexpected token for SHOW SLAVE");
                case STATUS:
                    switch(lexer.nextToken()) {
                        case KW_LIKE:
                            tempStr = like();
                            return new ShowStatus(VariableScope.SESSION, tempStr);
                        case KW_WHERE:
                            tempExpr = where();
                            return new ShowStatus(VariableScope.SESSION, tempExpr);
                        default:
                            return new ShowStatus(VariableScope.SESSION);
                    }
                case STORAGE:
                    lexer.nextToken();
                    matchIdentifier("ENGINES");
                    return new ShowEngines();
                case TABLES:
                    tempId = null;
                    switch(lexer.nextToken()) {
                        case KW_IN:
                        case KW_FROM:
                            lexer.nextToken();
                            tempId = identifier();
                    }
                    switch(lexer.token()) {
                        case KW_LIKE:
                            tempStr = like();
                            return new ShowTables(false, tempId, tempStr);
                        case KW_WHERE:
                            tempExpr = where();
                            return new ShowTables(false, tempId, tempExpr);
                        default:
                            return new ShowTables(false, tempId);
                    }
                case TRIGGERS:
                    tempId = null;
                    switch(lexer.nextToken()) {
                        case KW_IN:
                        case KW_FROM:
                            lexer.nextToken();
                            tempId = identifier();
                    }
                    switch(lexer.token()) {
                        case KW_LIKE:
                            tempStr = like();
                            return new ShowTriggers(tempId, tempStr);
                        case KW_WHERE:
                            tempExpr = where();
                            return new ShowTriggers(tempId, tempExpr);
                        default:
                            return new ShowTriggers(tempId);
                    }
                case VARIABLES:
                    switch(lexer.nextToken()) {
                        case KW_LIKE:
                            tempStr = like();
                            return new ShowVariables(VariableScope.SESSION, tempStr);
                        case KW_WHERE:
                            tempExpr = where();
                            return new ShowVariables(VariableScope.SESSION, tempExpr);
                        default:
                            return new ShowVariables(VariableScope.SESSION);
                    }
                case WARNINGS:
                    lexer.nextToken();
                    tempLimit = limit();
                    return new ShowWarnings(false, tempLimit);
            }
            break;
    }
    throw err("unexpect token for SHOW");
}
Also used : ShowTables(com.alibaba.cobar.parser.ast.stmt.dal.ShowTables) ShowBinaryLog(com.alibaba.cobar.parser.ast.stmt.dal.ShowBinaryLog) ShowProcedureStatus(com.alibaba.cobar.parser.ast.stmt.dal.ShowProcedureStatus) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString) ShowFunctionCode(com.alibaba.cobar.parser.ast.stmt.dal.ShowFunctionCode) ShowSlaveStatus(com.alibaba.cobar.parser.ast.stmt.dal.ShowSlaveStatus) ShowBinLogEvent(com.alibaba.cobar.parser.ast.stmt.dal.ShowBinLogEvent) Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) ShowFunctionStatus(com.alibaba.cobar.parser.ast.stmt.dal.ShowFunctionStatus) ShowCollation(com.alibaba.cobar.parser.ast.stmt.dal.ShowCollation) ShowProcedureCode(com.alibaba.cobar.parser.ast.stmt.dal.ShowProcedureCode) ShowCharaterSet(com.alibaba.cobar.parser.ast.stmt.dal.ShowCharaterSet) ShowErrors(com.alibaba.cobar.parser.ast.stmt.dal.ShowErrors) ShowProcesslist(com.alibaba.cobar.parser.ast.stmt.dal.ShowProcesslist) ShowMasterStatus(com.alibaba.cobar.parser.ast.stmt.dal.ShowMasterStatus) ShowStatus(com.alibaba.cobar.parser.ast.stmt.dal.ShowStatus) ShowVariables(com.alibaba.cobar.parser.ast.stmt.dal.ShowVariables) ShowProfiles(com.alibaba.cobar.parser.ast.stmt.dal.ShowProfiles) ShowTriggers(com.alibaba.cobar.parser.ast.stmt.dal.ShowTriggers) ShowDatabases(com.alibaba.cobar.parser.ast.stmt.dal.ShowDatabases) ShowEngines(com.alibaba.cobar.parser.ast.stmt.dal.ShowEngines) ShowWarnings(com.alibaba.cobar.parser.ast.stmt.dal.ShowWarnings) ShowEvents(com.alibaba.cobar.parser.ast.stmt.dal.ShowEvents) ShowAuthors(com.alibaba.cobar.parser.ast.stmt.dal.ShowAuthors) ShowSlaveHosts(com.alibaba.cobar.parser.ast.stmt.dal.ShowSlaveHosts) ShowPlugins(com.alibaba.cobar.parser.ast.stmt.dal.ShowPlugins) ShowPrivileges(com.alibaba.cobar.parser.ast.stmt.dal.ShowPrivileges) Expression(com.alibaba.cobar.parser.ast.expression.Expression) VariableExpression(com.alibaba.cobar.parser.ast.expression.primary.VariableExpression) ShowGrants(com.alibaba.cobar.parser.ast.stmt.dal.ShowGrants) ShowCreate(com.alibaba.cobar.parser.ast.stmt.dal.ShowCreate) ShowTableStatus(com.alibaba.cobar.parser.ast.stmt.dal.ShowTableStatus) ShowContributors(com.alibaba.cobar.parser.ast.stmt.dal.ShowContributors) Limit(com.alibaba.cobar.parser.ast.fragment.Limit) ShowEngine(com.alibaba.cobar.parser.ast.stmt.dal.ShowEngine) ShowOpenTables(com.alibaba.cobar.parser.ast.stmt.dal.ShowOpenTables)

Example 5 with Identifier

use of com.alibaba.cobar.parser.ast.expression.primary.Identifier in project cobar by alibaba.

the class MySQLMTSParser method rollback.

/**
     * first token <code>ROLLBACK</code> is scanned but not yet consumed
     * 
     * <pre>
     *         ROLLBACK [WORK] TO [SAVEPOINT] identifier
     *         ROLLBACK [WORK] [AND [NO] CHAIN | [NO] RELEASE]
     * </pre>
     */
public MTSRollbackStatement rollback() throws SQLSyntaxErrorException {
    // matchIdentifier("ROLLBACK"); // for performance issue, change to
    // follow:
    lexer.nextToken();
    SpecialIdentifier siTemp = specialIdentifiers.get(lexer.stringValueUppercase());
    if (siTemp == SpecialIdentifier.WORK) {
        lexer.nextToken();
    }
    switch(lexer.token()) {
        case EOF:
            return new MTSRollbackStatement(MTSRollbackStatement.CompleteType.UN_DEF);
        case KW_TO:
            lexer.nextToken();
            String str = lexer.stringValueUppercase();
            if (specialIdentifiers.get(str) == SpecialIdentifier.SAVEPOINT) {
                lexer.nextToken();
            }
            Identifier savepoint = identifier();
            match(EOF);
            return new MTSRollbackStatement(savepoint);
        case KW_AND:
            lexer.nextToken();
            siTemp = specialIdentifiers.get(lexer.stringValueUppercase());
            if (siTemp == SpecialIdentifier.NO) {
                lexer.nextToken();
                matchIdentifier("CHAIN");
                match(EOF);
                return new MTSRollbackStatement(MTSRollbackStatement.CompleteType.NO_CHAIN);
            }
            matchIdentifier("CHAIN");
            match(EOF);
            return new MTSRollbackStatement(MTSRollbackStatement.CompleteType.CHAIN);
        case KW_RELEASE:
            lexer.nextToken();
            match(EOF);
            return new MTSRollbackStatement(MTSRollbackStatement.CompleteType.RELEASE);
        case IDENTIFIER:
            siTemp = specialIdentifiers.get(lexer.stringValueUppercase());
            if (siTemp == SpecialIdentifier.NO) {
                lexer.nextToken();
                match(KW_RELEASE);
                match(EOF);
                return new MTSRollbackStatement(MTSRollbackStatement.CompleteType.NO_RELEASE);
            }
        default:
            throw err("unrecognized complete type: " + lexer.token());
    }
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) MTSRollbackStatement(com.alibaba.cobar.parser.ast.stmt.mts.MTSRollbackStatement)

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