Search in sources :

Example 46 with Identifier

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

the class PartitionKeyVisitor method visit.

@Override
public void visit(DMLUpdateStatement node) {
    TableReference tr = node.getTableRefs();
    visitChild(1, false, false, tr);
    List<Pair<Identifier, Expression>> assignmentList = node.getValues();
    if (assignmentList != null && !assignmentList.isEmpty()) {
        List<ASTNode> list = new ArrayList<ASTNode>(assignmentList.size() * 2);
        for (Pair<Identifier, Expression> p : assignmentList) {
            if (p == null)
                continue;
            list.add(p.getKey());
            list.add(p.getValue());
        }
        visitChild(2, false, false, list);
    }
    Expression where = node.getWhere();
    visitChild(2, verdictColumn, false, where);
    OrderBy order = node.getOrderBy();
    visitChild(2, false, false, order);
}
Also used : OrderBy(com.alibaba.cobar.parser.ast.fragment.OrderBy) TableReference(com.alibaba.cobar.parser.ast.fragment.tableref.TableReference) 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) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) LogicalOrExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression) ReplacableExpression(com.alibaba.cobar.parser.ast.expression.ReplacableExpression) 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) 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) ArrayList(java.util.ArrayList) ASTNode(com.alibaba.cobar.parser.ast.ASTNode) Pair(com.alibaba.cobar.parser.util.Pair)

Example 47 with Identifier

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

the class PartitionKeyVisitor method insertReplace.

private void insertReplace(DMLInsertReplaceStatement node) {
    Identifier table = node.getTable();
    List<Identifier> collist = node.getColumnNameList();
    QueryExpression query = node.getSelect();
    List<RowExpression> rows = node.getRowList();
    tableAsTableFactor(table);
    String tableName = table.getIdTextUpUnescape();
    visitChild(2, false, false, collist);
    if (query != null) {
        query.accept(this);
        return;
    }
    for (RowExpression row : rows) {
        visitChild(2, false, false, row);
    }
    Map<String, List<Object>> colVals = ensureColumnValueByTable(tableName);
    Map<String, Map<Object, Set<Pair<Expression, ASTNode>>>> colValsIndex = ensureColumnValueIndexByTable(tableName);
    if (collist != null) {
        for (int i = 0; i < collist.size(); ++i) {
            String colName = collist.get(i).getIdTextUpUnescape();
            if (isRuledColumn(tableName, colName)) {
                List<Object> valueList = ensureColumnValueList(colVals, colName);
                Map<Object, Set<Pair<Expression, ASTNode>>> valMap = ensureColumnValueIndexObjMap(colValsIndex, colName);
                for (RowExpression row : rows) {
                    Expression expr = row.getRowExprList().get(i);
                    Object value = expr == null ? null : expr.evaluation(evaluationParameter);
                    if (value != Expression.UNEVALUATABLE) {
                        valueList.add(value);
                        addIntoColumnValueIndex(valMap, value, row, node);
                    }
                }
            }
        }
    }
}
Also used : SmallSet(com.alibaba.cobar.util.SmallSet) Set(java.util.Set) HashSet(java.util.HashSet) ShowCharaterSet(com.alibaba.cobar.parser.ast.stmt.dal.ShowCharaterSet) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString) IndexHint(com.alibaba.cobar.parser.ast.fragment.tableref.IndexHint) 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) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) LogicalOrExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression) ReplacableExpression(com.alibaba.cobar.parser.ast.expression.ReplacableExpression) 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) 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) ASTNode(com.alibaba.cobar.parser.ast.ASTNode) InExpressionList(com.alibaba.cobar.parser.ast.expression.misc.InExpressionList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) Map(java.util.Map) HashMap(java.util.HashMap) Pair(com.alibaba.cobar.parser.util.Pair)

Example 48 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(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 49 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(TableRefFactor node) {
    Identifier table = node.getTable();
    table.accept(this);
    String alias = node.getAlias();
    if (alias != null) {
        appendable.append(" AS ").append(alias);
    }
    List<IndexHint> list = node.getHintList();
    if (list != null && !list.isEmpty()) {
        appendable.append(' ');
        printList(list, " ");
    }
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) IndexHint(com.alibaba.cobar.parser.ast.fragment.tableref.IndexHint) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString)

Example 50 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(MTSRollbackStatement node) {
    appendable.append("ROLLBACK");
    Identifier savepoint = node.getSavepoint();
    if (savepoint == null) {
        MTSRollbackStatement.CompleteType type = node.getCompleteType();
        switch(type) {
            case CHAIN:
                appendable.append(" AND CHAIN");
                break;
            case NO_CHAIN:
                appendable.append(" AND NO CHAIN");
                break;
            case NO_RELEASE:
                appendable.append(" NO RELEASE");
                break;
            case RELEASE:
                appendable.append(" RELEASE");
                break;
            case UN_DEF:
                break;
            default:
                throw new IllegalArgumentException("unrecgnized complete type: " + type);
        }
    } else {
        appendable.append(" TO SAVEPOINT ");
        savepoint.accept(this);
    }
}
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