Search in sources :

Example 16 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(ShowOpenTables node) {
    appendable.append("SHOW OPEN TABLES");
    Identifier db = node.getSchema();
    if (db != null) {
        appendable.append(" FROM ");
        db.accept(this);
    }
    printLikeOrWhere(node.getPattern(), node.getWhere());
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier)

Example 17 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(ShowTableStatus node) {
    appendable.append("SHOW TABLE STATUS");
    Identifier schema = node.getDatabase();
    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)

Example 18 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(ShowEvents node) {
    appendable.append("SHOW EVENTS");
    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)

Example 19 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(ShowTriggers node) {
    appendable.append("SHOW TRIGGERS");
    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)

Example 20 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(DMLInsertStatement node) {
    appendable.append("INSERT ");
    switch(node.getMode()) {
        case DELAY:
            appendable.append("DELAYED ");
            break;
        case HIGH:
            appendable.append("HIGH_PRIORITY ");
            break;
        case LOW:
            appendable.append("LOW_PRIORITY ");
            break;
        case UNDEF:
            break;
        default:
            throw new IllegalArgumentException("unknown mode for INSERT: " + node.getMode());
    }
    if (node.isIgnore())
        appendable.append("IGNORE ");
    appendable.append("INTO ");
    node.getTable().accept(this);
    appendable.append(' ');
    List<Identifier> cols = node.getColumnNameList();
    if (cols != null && !cols.isEmpty()) {
        appendable.append('(');
        printList(cols);
        appendable.append(") ");
    }
    QueryExpression select = node.getSelect();
    if (select == null) {
        appendable.append("VALUES ");
        List<RowExpression> rows = node.getRowList();
        if (rows != null && !rows.isEmpty()) {
            boolean isFst = true;
            for (RowExpression row : rows) {
                if (row == null || row.getRowExprList().isEmpty())
                    continue;
                if (isFst)
                    isFst = false;
                else
                    appendable.append(", ");
                appendable.append('(');
                printList(row.getRowExprList());
                appendable.append(')');
            }
        } else {
            throw new IllegalArgumentException("at least one row for INSERT");
        }
    } else {
        select.accept(this);
    }
    List<Pair<Identifier, Expression>> dup = node.getDuplicateUpdate();
    if (dup != null && !dup.isEmpty()) {
        appendable.append(" ON DUPLICATE KEY UPDATE ");
        boolean isFst = true;
        for (Pair<Identifier, Expression> p : dup) {
            if (isFst)
                isFst = false;
            else
                appendable.append(", ");
            p.getKey().accept(this);
            appendable.append(" = ");
            p.getValue().accept(this);
        }
    }
}
Also used : 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) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) Pair(com.alibaba.cobar.parser.util.Pair)

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