Search in sources :

Example 11 with TableReference

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

the class PartitionKeyVisitor method visit.

@Override
public void visit(OuterJoin node) {
    TableReference tr1 = node.getLeftTableRef();
    TableReference tr2 = node.getRightTableRef();
    Expression on = node.getOnCond();
    visitChild(1, verdictColumn, verdictGroupFunc, tr1, tr2);
    visitChild(2, verdictColumn && isVerdictPassthroughWhere(on), false, on);
}
Also used : TableReference(com.alibaba.cobar.parser.ast.fragment.tableref.TableReference) 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)

Example 12 with TableReference

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

the class PartitionKeyVisitor method visit.

@Override
public void visit(InnerJoin node) {
    TableReference tr1 = node.getLeftTableRef();
    TableReference tr2 = node.getRightTableRef();
    Expression on = node.getOnCond();
    visitChild(1, verdictColumn, verdictGroupFunc, tr1, tr2);
    visitChild(2, verdictColumn && isVerdictPassthroughWhere(on), false, on);
}
Also used : TableReference(com.alibaba.cobar.parser.ast.fragment.tableref.TableReference) 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)

Example 13 with TableReference

use of com.alibaba.cobar.parser.ast.fragment.tableref.TableReference 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 14 with TableReference

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

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(InnerJoin node) {
    TableReference left = node.getLeftTableRef();
    boolean paren = left.getPrecedence() < node.getPrecedence();
    if (paren)
        appendable.append('(');
    left.accept(this);
    if (paren)
        appendable.append(')');
    appendable.append(" INNER JOIN ");
    TableReference right = node.getRightTableRef();
    paren = right.getPrecedence() <= node.getPrecedence();
    if (paren)
        appendable.append('(');
    right.accept(this);
    if (paren)
        appendable.append(')');
    Expression on = node.getOnCond();
    List<String> using = node.getUsing();
    if (on != null) {
        appendable.append(" ON ");
        on.accept(this);
    } else if (using != null) {
        appendable.append(" USING (");
        boolean isFst = true;
        for (String col : using) {
            if (isFst)
                isFst = false;
            else
                appendable.append(", ");
            appendable.append(col);
        }
        appendable.append(")");
    }
}
Also used : TableReference(com.alibaba.cobar.parser.ast.fragment.tableref.TableReference) 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) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString)

Example 15 with TableReference

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

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(OuterJoin node) {
    TableReference left = node.getLeftTableRef();
    boolean paren = left.getPrecedence() < node.getPrecedence();
    if (paren)
        appendable.append('(');
    left.accept(this);
    if (paren)
        appendable.append(')');
    if (node.isLeftJoin())
        appendable.append(" LEFT JOIN ");
    else
        appendable.append(" RIGHT JOIN ");
    TableReference right = node.getRightTableRef();
    paren = right.getPrecedence() <= node.getPrecedence();
    if (paren)
        appendable.append('(');
    right.accept(this);
    if (paren)
        appendable.append(')');
    Expression on = node.getOnCond();
    List<String> using = node.getUsing();
    if (on != null) {
        appendable.append(" ON ");
        on.accept(this);
    } else if (using != null) {
        appendable.append(" USING (");
        boolean isFst = true;
        for (String col : using) {
            if (isFst)
                isFst = false;
            else
                appendable.append(", ");
            appendable.append(col);
        }
        appendable.append(")");
    } else {
        throw new IllegalArgumentException("either ON or USING must be included for OUTER JOIN");
    }
}
Also used : TableReference(com.alibaba.cobar.parser.ast.fragment.tableref.TableReference) 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) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString)

Aggregations

TableReference (com.alibaba.cobar.parser.ast.fragment.tableref.TableReference)15 Expression (com.alibaba.cobar.parser.ast.expression.Expression)12 QueryExpression (com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)11 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)10 LogicalAndExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression)10 BinaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression)9 PolyadicOperatorExpression (com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression)9 UnaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression)9 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)9 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)9 ComparisionNullSafeEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression)9 InExpression (com.alibaba.cobar.parser.ast.expression.comparison.InExpression)9 LogicalOrExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression)9 UserExpression (com.alibaba.cobar.parser.ast.expression.misc.UserExpression)9 CaseWhenOperatorExpression (com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression)9 MatchExpression (com.alibaba.cobar.parser.ast.expression.primary.MatchExpression)9 RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)9 FunctionExpression (com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression)9 LikeExpression (com.alibaba.cobar.parser.ast.expression.string.LikeExpression)9 CollateExpression (com.alibaba.cobar.parser.ast.expression.type.CollateExpression)9