Search in sources :

Example 91 with Expression

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

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(BetweenAndExpression node) {
    Expression comparee = node.getFirst();
    boolean paren = comparee.getPrecedence() <= node.getPrecedence();
    if (paren)
        appendable.append('(');
    comparee.accept(this);
    if (paren)
        appendable.append(')');
    if (node.isNot())
        appendable.append(" NOT BETWEEN ");
    else
        appendable.append(" BETWEEN ");
    Expression start = node.getSecond();
    paren = start.getPrecedence() < node.getPrecedence();
    if (paren)
        appendable.append('(');
    start.accept(this);
    if (paren)
        appendable.append(')');
    appendable.append(" AND ");
    Expression end = node.getThird();
    paren = end.getPrecedence() < node.getPrecedence();
    if (paren)
        appendable.append('(');
    end.accept(this);
    if (paren)
        appendable.append(')');
}
Also used : 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)

Example 92 with Expression

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

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(MatchExpression node) {
    appendable.append("MATCH (");
    printList(node.getColumns());
    appendable.append(") AGAINST (");
    Expression pattern = node.getPattern();
    boolean inparen = containsCompIn(pattern);
    if (inparen)
        appendable.append('(');
    pattern.accept(this);
    if (inparen)
        appendable.append(')');
    switch(node.getModifier()) {
        case IN_BOOLEAN_MODE:
            appendable.append(" IN BOOLEAN MODE");
            break;
        case IN_NATURAL_LANGUAGE_MODE:
            appendable.append(" IN NATURAL LANGUAGE MODE");
            break;
        case IN_NATURAL_LANGUAGE_MODE_WITH_QUERY_EXPANSION:
            appendable.append(" IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION");
            break;
        case WITH_QUERY_EXPANSION:
            appendable.append(" WITH QUERY EXPANSION");
            break;
        case _DEFAULT:
            break;
        default:
            throw new IllegalArgumentException("unkown modifier for match expression: " + node.getModifier());
    }
    appendable.append(')');
}
Also used : 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)

Example 93 with Expression

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

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(PolyadicOperatorExpression node) {
    for (int i = 0, len = node.getArity(); i < len; ++i) {
        if (i > 0)
            appendable.append(' ').append(node.getOperator()).append(' ');
        Expression operand = node.getOperand(i);
        boolean paren = operand.getPrecedence() < node.getPrecedence();
        if (paren)
            appendable.append('(');
        operand.accept(this);
        if (paren)
            appendable.append(')');
    }
}
Also used : 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) IndexHint(com.alibaba.cobar.parser.ast.fragment.tableref.IndexHint)

Example 94 with Expression

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

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(GroupConcat node) {
    String functionName = node.getFunctionName();
    appendable.append(functionName).append('(');
    if (node.isDistinct()) {
        appendable.append("DISTINCT ");
    }
    printList(node.getArguments());
    Expression orderBy = node.getOrderBy();
    if (orderBy != null) {
        appendable.append(" ORDER BY ");
        orderBy.accept(this);
        if (node.isDesc())
            appendable.append(" DESC");
        else
            appendable.append(" ASC");
        List<Expression> list = node.getAppendedColumnNames();
        if (list != null && !list.isEmpty()) {
            appendable.append(", ");
            printList(list);
        }
    }
    String sep = node.getSeparator();
    if (sep != null) {
        appendable.append(" SEPARATOR ").append(sep);
    }
    appendable.append(')');
}
Also used : 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 95 with Expression

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

the class PartitionByString method constructFunction.

@Override
public FunctionExpression constructFunction(List<Expression> arguments) {
    if (arguments == null || arguments.size() != 1) {
        throw new IllegalArgumentException("function " + getFunctionName() + " must have 1 argument but is " + arguments);
    }
    Object[] args = new Object[arguments.size()];
    int i = -1;
    for (Expression arg : arguments) {
        args[++i] = arg;
    }
    return (FunctionExpression) constructMe(args);
}
Also used : FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression)

Aggregations

Expression (com.alibaba.cobar.parser.ast.expression.Expression)128 RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)96 QueryExpression (com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)93 InExpression (com.alibaba.cobar.parser.ast.expression.comparison.InExpression)91 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)88 LogicalAndExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression)88 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)87 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)87 ComparisionNullSafeEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression)87 LogicalOrExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression)87 UserExpression (com.alibaba.cobar.parser.ast.expression.misc.UserExpression)87 CaseWhenOperatorExpression (com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression)87 LikeExpression (com.alibaba.cobar.parser.ast.expression.string.LikeExpression)87 CollateExpression (com.alibaba.cobar.parser.ast.expression.type.CollateExpression)87 FunctionExpression (com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression)76 MatchExpression (com.alibaba.cobar.parser.ast.expression.primary.MatchExpression)71 BinaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression)58 PolyadicOperatorExpression (com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression)58 UnaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression)58 ArithmeticAddExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticAddExpression)45