Search in sources :

Example 1 with ShowProfile

use of com.alibaba.cobar.parser.ast.stmt.dal.ShowProfile in project cobar by alibaba.

the class MySQLDALParser method showProfile.

private ShowProfile showProfile() throws SQLSyntaxErrorException {
    lexer.nextToken();
    List<ShowProfile.Type> types = new LinkedList<ShowProfile.Type>();
    ShowProfile.Type type = showPrifileType();
    if (type == null) {
        types = Collections.emptyList();
    } else if (lexer.token() == PUNC_COMMA) {
        types = new LinkedList<ShowProfile.Type>();
        types.add(type);
        for (; lexer.token() == PUNC_COMMA; ) {
            lexer.nextToken();
            type = showPrifileType();
            types.add(type);
        }
    } else {
        types = new ArrayList<ShowProfile.Type>();
        types.add(type);
    }
    Expression forQuery = null;
    if (lexer.token() == KW_FOR) {
        lexer.nextToken();
        matchIdentifier("QUERY");
        forQuery = exprParser.expression();
    }
    Limit limit = limit();
    return new ShowProfile(types, forQuery, limit);
}
Also used : Expression(com.alibaba.cobar.parser.ast.expression.Expression) VariableExpression(com.alibaba.cobar.parser.ast.expression.primary.VariableExpression) ShowProfile(com.alibaba.cobar.parser.ast.stmt.dal.ShowProfile) ArrayList(java.util.ArrayList) Limit(com.alibaba.cobar.parser.ast.fragment.Limit) LinkedList(java.util.LinkedList)

Example 2 with ShowProfile

use of com.alibaba.cobar.parser.ast.stmt.dal.ShowProfile in project cobar by alibaba.

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(ShowProfile node) {
    appendable.append("SHOW PROFILE");
    List<ShowProfile.Type> types = node.getTypes();
    boolean isFst = true;
    for (ShowProfile.Type type : types) {
        if (isFst) {
            isFst = false;
            appendable.append(' ');
        } else {
            appendable.append(", ");
        }
        appendable.append(type.name().replace('_', ' '));
    }
    Expression query = node.getForQuery();
    if (query != null) {
        appendable.append(" FOR QUERY ");
        query.accept(this);
    }
    Limit limit = node.getLimit();
    if (limit != null) {
        appendable.append(' ');
        limit.accept(this);
    }
}
Also used : DataType(com.alibaba.cobar.parser.ast.fragment.ddl.datatype.DataType) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) MatchExpression(com.alibaba.cobar.parser.ast.expression.primary.MatchExpression) VariableExpression(com.alibaba.cobar.parser.ast.expression.primary.VariableExpression) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) LogicalOrExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression) LogicalAndExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression) UnaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) TernaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.TernaryOperatorExpression) CollateExpression(com.alibaba.cobar.parser.ast.expression.type.CollateExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression) CaseWhenOperatorExpression(com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression) UserExpression(com.alibaba.cobar.parser.ast.expression.misc.UserExpression) PolyadicOperatorExpression(com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression) BinaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) ShowProfile(com.alibaba.cobar.parser.ast.stmt.dal.ShowProfile) Limit(com.alibaba.cobar.parser.ast.fragment.Limit)

Aggregations

Expression (com.alibaba.cobar.parser.ast.expression.Expression)2 VariableExpression (com.alibaba.cobar.parser.ast.expression.primary.VariableExpression)2 Limit (com.alibaba.cobar.parser.ast.fragment.Limit)2 ShowProfile (com.alibaba.cobar.parser.ast.stmt.dal.ShowProfile)2 BinaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression)1 PolyadicOperatorExpression (com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression)1 TernaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.TernaryOperatorExpression)1 UnaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression)1 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)1 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)1 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)1 ComparisionNullSafeEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression)1 InExpression (com.alibaba.cobar.parser.ast.expression.comparison.InExpression)1 LogicalAndExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression)1 LogicalOrExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression)1 QueryExpression (com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)1 UserExpression (com.alibaba.cobar.parser.ast.expression.misc.UserExpression)1 CaseWhenOperatorExpression (com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression)1 MatchExpression (com.alibaba.cobar.parser.ast.expression.primary.MatchExpression)1 RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)1