Search in sources :

Example 6 with ASTNode

use of com.alibaba.cobar.parser.ast.ASTNode in project cobar by alibaba.

the class PartitionKeyVisitor method visit.

@Override
public void visit(DMLInsertStatement node) {
    insertReplace(node);
    List<Pair<Identifier, Expression>> dup = node.getDuplicateUpdate();
    if (dup != null) {
        ASTNode[] duplist = new ASTNode[dup.size() * 2];
        int i = 0;
        for (Pair<Identifier, Expression> p : dup) {
            Identifier key = null;
            Expression value = null;
            if (p != null) {
                key = p.getKey();
                value = p.getValue();
            }
            duplist[i++] = key;
            duplist[i++] = value;
        }
        visitChild(2, false, false, duplist);
    }
}
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) 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) IndexHint(com.alibaba.cobar.parser.ast.fragment.tableref.IndexHint) Pair(com.alibaba.cobar.parser.util.Pair)

Example 7 with ASTNode

use of com.alibaba.cobar.parser.ast.ASTNode in project cobar by alibaba.

the class PartitionKeyVisitor method visitChild.

private void visitChild(int idLevel, boolean verdictColumn, boolean verdictGroupFunc, ASTNode... nodes) {
    if (nodes == null || nodes.length <= 0)
        return;
    int oldLevel = this.idLevel;
    boolean oldVerdict = this.verdictColumn;
    boolean oldverdictGroupFunc = this.verdictGroupFunc;
    this.idLevel = idLevel;
    this.verdictColumn = verdictColumn;
    this.verdictGroupFunc = verdictGroupFunc;
    try {
        for (ASTNode node : nodes) {
            if (node != null)
                node.accept(this);
        }
    } finally {
        this.verdictColumn = oldVerdict;
        this.idLevel = oldLevel;
        this.verdictGroupFunc = oldverdictGroupFunc;
    }
}
Also used : ASTNode(com.alibaba.cobar.parser.ast.ASTNode) IndexHint(com.alibaba.cobar.parser.ast.fragment.tableref.IndexHint)

Example 8 with ASTNode

use of com.alibaba.cobar.parser.ast.ASTNode 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) ASTNode(com.alibaba.cobar.parser.ast.ASTNode) ArrayList(java.util.ArrayList) Pair(com.alibaba.cobar.parser.util.Pair)

Example 9 with ASTNode

use of com.alibaba.cobar.parser.ast.ASTNode in project cobar by alibaba.

the class PartitionKeyVisitor method visitChild.

private void visitChild(int idLevel, boolean verdictColumn, boolean verdictGroupFunc, List<? extends ASTNode> nodes) {
    if (nodes == null || nodes.isEmpty())
        return;
    int oldLevel = this.idLevel;
    boolean oldVerdict = this.verdictColumn;
    boolean oldverdictGroupFunc = this.verdictGroupFunc;
    this.idLevel = idLevel;
    this.verdictColumn = verdictColumn;
    this.verdictGroupFunc = verdictGroupFunc;
    try {
        for (ASTNode node : nodes) {
            if (node != null)
                node.accept(this);
        }
    } finally {
        this.verdictColumn = oldVerdict;
        this.idLevel = oldLevel;
        this.verdictGroupFunc = oldverdictGroupFunc;
    }
}
Also used : ASTNode(com.alibaba.cobar.parser.ast.ASTNode) IndexHint(com.alibaba.cobar.parser.ast.fragment.tableref.IndexHint)

Aggregations

ASTNode (com.alibaba.cobar.parser.ast.ASTNode)9 Expression (com.alibaba.cobar.parser.ast.expression.Expression)7 ReplacableExpression (com.alibaba.cobar.parser.ast.expression.ReplacableExpression)7 InExpression (com.alibaba.cobar.parser.ast.expression.comparison.InExpression)7 RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)7 Pair (com.alibaba.cobar.parser.util.Pair)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 BinaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression)4 PolyadicOperatorExpression (com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression)4 UnaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression)4 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)4 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)4 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)4 ComparisionNullSafeEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression)4 LogicalAndExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression)4 LogicalOrExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression)4 InExpressionList (com.alibaba.cobar.parser.ast.expression.misc.InExpressionList)4 QueryExpression (com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)4 UserExpression (com.alibaba.cobar.parser.ast.expression.misc.UserExpression)4