Search in sources :

Example 11 with OrderBy

use of com.alibaba.cobar.parser.ast.fragment.OrderBy in project cobar by alibaba.

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(DMLUpdateStatement node) {
    appendable.append("UPDATE ");
    if (node.isLowPriority()) {
        appendable.append("LOW_PRIORITY ");
    }
    if (node.isIgnore()) {
        appendable.append("IGNORE ");
    }
    node.getTableRefs().accept(this);
    appendable.append(" SET ");
    boolean isFst = true;
    for (Pair<Identifier, Expression> p : node.getValues()) {
        if (isFst)
            isFst = false;
        else
            appendable.append(", ");
        p.getKey().accept(this);
        appendable.append(" = ");
        p.getValue().accept(this);
    }
    Expression where = node.getWhere();
    if (where != null) {
        appendable.append(" WHERE ");
        where.accept(this);
    }
    OrderBy order = node.getOrderBy();
    if (order != null) {
        appendable.append(' ');
        order.accept(this);
    }
    Limit limit = node.getLimit();
    if (limit != null) {
        appendable.append(' ');
        limit.accept(this);
    }
}
Also used : OrderBy(com.alibaba.cobar.parser.ast.fragment.OrderBy) Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) 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) Limit(com.alibaba.cobar.parser.ast.fragment.Limit)

Example 12 with OrderBy

use of com.alibaba.cobar.parser.ast.fragment.OrderBy in project cobar by alibaba.

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(DMLSelectUnionStatement node) {
    List<DMLSelectStatement> list = node.getSelectStmtList();
    if (list == null || list.isEmpty()) {
        throw new IllegalArgumentException("SELECT UNION must have at least one SELECT");
    }
    final int fstDist = node.getFirstDistinctIndex();
    int i = 0;
    for (DMLSelectStatement select : list) {
        if (i > 0) {
            appendable.append(" UNION ");
            if (i > fstDist) {
                appendable.append("ALL ");
            }
        }
        appendable.append('(');
        select.accept(this);
        appendable.append(')');
        ++i;
    }
    OrderBy order = node.getOrderBy();
    if (order != null) {
        appendable.append(' ');
        order.accept(this);
    }
    Limit limit = node.getLimit();
    if (limit != null) {
        appendable.append(' ');
        limit.accept(this);
    }
}
Also used : OrderBy(com.alibaba.cobar.parser.ast.fragment.OrderBy) DMLSelectStatement(com.alibaba.cobar.parser.ast.stmt.dml.DMLSelectStatement) Limit(com.alibaba.cobar.parser.ast.fragment.Limit) IndexHint(com.alibaba.cobar.parser.ast.fragment.tableref.IndexHint)

Aggregations

OrderBy (com.alibaba.cobar.parser.ast.fragment.OrderBy)12 Expression (com.alibaba.cobar.parser.ast.expression.Expression)10 QueryExpression (com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)7 Limit (com.alibaba.cobar.parser.ast.fragment.Limit)7 BinaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression)6 PolyadicOperatorExpression (com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression)6 UnaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression)6 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)6 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)6 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)6 ComparisionNullSafeEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression)6 InExpression (com.alibaba.cobar.parser.ast.expression.comparison.InExpression)6 LogicalAndExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression)6 LogicalOrExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression)6 UserExpression (com.alibaba.cobar.parser.ast.expression.misc.UserExpression)6 CaseWhenOperatorExpression (com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression)6 Identifier (com.alibaba.cobar.parser.ast.expression.primary.Identifier)6 MatchExpression (com.alibaba.cobar.parser.ast.expression.primary.MatchExpression)6 RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)6 FunctionExpression (com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression)6