Search in sources :

Example 1 with ComparisionLessOrGreaterThanExpression

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

the class MySQLExprParser method comparisionExpression.

/**
     * <code>BETWEEN ... AND</code> has lower precedence than other comparison
     * operator
     */
private Expression comparisionExpression() throws SQLSyntaxErrorException {
    Expression temp;
    for (Expression fst = bitOrExpression(null, null); ; ) {
        switch(lexer.token()) {
            case KW_NOT:
                lexer.nextToken();
                switch(lexer.token()) {
                    case KW_BETWEEN:
                        lexer.nextToken();
                        Expression snd = comparisionExpression();
                        match(KW_AND);
                        Expression trd = comparisionExpression();
                        return new BetweenAndExpression(true, fst, snd, trd).setCacheEvalRst(cacheEvalRst);
                    case KW_RLIKE:
                    case KW_REGEXP:
                        lexer.nextToken();
                        temp = bitOrExpression(null, null);
                        fst = new RegexpExpression(true, fst, temp).setCacheEvalRst(cacheEvalRst);
                        continue;
                    case KW_LIKE:
                        lexer.nextToken();
                        temp = bitOrExpression(null, null);
                        Expression escape = null;
                        if (equalsIdentifier("ESCAPE") >= 0) {
                            lexer.nextToken();
                            escape = bitOrExpression(null, null);
                        }
                        fst = new LikeExpression(true, fst, temp, escape).setCacheEvalRst(cacheEvalRst);
                        continue;
                    case KW_IN:
                        if (lexer.nextToken() != PUNC_LEFT_PAREN) {
                            lexer.addCacheToke(KW_IN);
                            return fst;
                        }
                        Expression in = rightOprandOfIn();
                        fst = new InExpression(true, fst, in).setCacheEvalRst(cacheEvalRst);
                        continue;
                    default:
                        throw err("unexpect token after NOT: " + lexer.token());
                }
            case KW_BETWEEN:
                lexer.nextToken();
                Expression snd = comparisionExpression();
                match(KW_AND);
                Expression trd = comparisionExpression();
                return new BetweenAndExpression(false, fst, snd, trd).setCacheEvalRst(cacheEvalRst);
            case KW_RLIKE:
            case KW_REGEXP:
                lexer.nextToken();
                temp = bitOrExpression(null, null);
                fst = new RegexpExpression(false, fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            case KW_LIKE:
                lexer.nextToken();
                temp = bitOrExpression(null, null);
                Expression escape = null;
                if (equalsIdentifier("ESCAPE") >= 0) {
                    lexer.nextToken();
                    escape = bitOrExpression(null, null);
                }
                fst = new LikeExpression(false, fst, temp, escape).setCacheEvalRst(cacheEvalRst);
                continue;
            case KW_IN:
                if (lexer.nextToken() != PUNC_LEFT_PAREN) {
                    lexer.addCacheToke(KW_IN);
                    return fst;
                }
                temp = rightOprandOfIn();
                fst = new InExpression(false, fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            case KW_IS:
                switch(lexer.nextToken()) {
                    case KW_NOT:
                        switch(lexer.nextToken()) {
                            case LITERAL_NULL:
                                lexer.nextToken();
                                fst = new ComparisionIsExpression(fst, ComparisionIsExpression.IS_NOT_NULL).setCacheEvalRst(cacheEvalRst);
                                continue;
                            case LITERAL_BOOL_FALSE:
                                lexer.nextToken();
                                fst = new ComparisionIsExpression(fst, ComparisionIsExpression.IS_NOT_FALSE).setCacheEvalRst(cacheEvalRst);
                                continue;
                            case LITERAL_BOOL_TRUE:
                                lexer.nextToken();
                                fst = new ComparisionIsExpression(fst, ComparisionIsExpression.IS_NOT_TRUE).setCacheEvalRst(cacheEvalRst);
                                continue;
                            default:
                                matchIdentifier("UNKNOWN");
                                fst = new ComparisionIsExpression(fst, ComparisionIsExpression.IS_NOT_UNKNOWN).setCacheEvalRst(cacheEvalRst);
                                continue;
                        }
                    case LITERAL_NULL:
                        lexer.nextToken();
                        fst = new ComparisionIsExpression(fst, ComparisionIsExpression.IS_NULL).setCacheEvalRst(cacheEvalRst);
                        continue;
                    case LITERAL_BOOL_FALSE:
                        lexer.nextToken();
                        fst = new ComparisionIsExpression(fst, ComparisionIsExpression.IS_FALSE).setCacheEvalRst(cacheEvalRst);
                        continue;
                    case LITERAL_BOOL_TRUE:
                        lexer.nextToken();
                        fst = new ComparisionIsExpression(fst, ComparisionIsExpression.IS_TRUE).setCacheEvalRst(cacheEvalRst);
                        continue;
                    default:
                        matchIdentifier("UNKNOWN");
                        fst = new ComparisionIsExpression(fst, ComparisionIsExpression.IS_UNKNOWN).setCacheEvalRst(cacheEvalRst);
                        continue;
                }
            case OP_EQUALS:
                lexer.nextToken();
                temp = anyAllExpression();
                fst = new ComparisionEqualsExpression(fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            case OP_NULL_SAFE_EQUALS:
                lexer.nextToken();
                temp = bitOrExpression(null, null);
                fst = new ComparisionNullSafeEqualsExpression(fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            case OP_GREATER_OR_EQUALS:
                lexer.nextToken();
                temp = anyAllExpression();
                fst = new ComparisionGreaterThanOrEqualsExpression(fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            case OP_GREATER_THAN:
                lexer.nextToken();
                temp = anyAllExpression();
                fst = new ComparisionGreaterThanExpression(fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            case OP_LESS_OR_EQUALS:
                lexer.nextToken();
                temp = anyAllExpression();
                fst = new ComparisionLessThanOrEqualsExpression(fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            case OP_LESS_THAN:
                lexer.nextToken();
                temp = anyAllExpression();
                fst = new ComparisionLessThanExpression(fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            case OP_LESS_OR_GREATER:
                lexer.nextToken();
                temp = anyAllExpression();
                fst = new ComparisionLessOrGreaterThanExpression(fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            case OP_NOT_EQUALS:
                lexer.nextToken();
                temp = anyAllExpression();
                fst = new ComparisionNotEqualsExpression(fst, temp).setCacheEvalRst(cacheEvalRst);
                continue;
            default:
                if (equalsIdentifier("SOUNDS") >= 0) {
                    lexer.nextToken();
                    match(KW_LIKE);
                    temp = bitOrExpression(null, null);
                    fst = new SoundsLikeExpression(fst, temp).setCacheEvalRst(cacheEvalRst);
                    continue;
                }
                return fst;
        }
    }
}
Also used : ComparisionGreaterThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanOrEqualsExpression) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) ComparisionLessThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanOrEqualsExpression) ComparisionLessThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanExpression) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) SoundsLikeExpression(com.alibaba.cobar.parser.ast.expression.string.SoundsLikeExpression) ComparisionLessOrGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessOrGreaterThanExpression) SubqueryAllExpression(com.alibaba.cobar.parser.ast.expression.misc.SubqueryAllExpression) MinusExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.MinusExpression) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) BitAndExpression(com.alibaba.cobar.parser.ast.expression.bit.BitAndExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) NegativeValueExpression(com.alibaba.cobar.parser.ast.expression.logical.NegativeValueExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) CastBinaryExpression(com.alibaba.cobar.parser.ast.expression.type.CastBinaryExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) BitInvertExpression(com.alibaba.cobar.parser.ast.expression.bit.BitInvertExpression) BitXORExpression(com.alibaba.cobar.parser.ast.expression.bit.BitXORExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) BitShiftExpression(com.alibaba.cobar.parser.ast.expression.bit.BitShiftExpression) BitOrExpression(com.alibaba.cobar.parser.ast.expression.bit.BitOrExpression) ComparisionGreaterThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanOrEqualsExpression) 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) ComparisionGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanExpression) ComparisionLessOrGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessOrGreaterThanExpression) SubqueryAnyExpression(com.alibaba.cobar.parser.ast.expression.misc.SubqueryAnyExpression) RegexpExpression(com.alibaba.cobar.parser.ast.expression.string.RegexpExpression) LogicalAndExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression) ArithmeticMultiplyExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticMultiplyExpression) ComparisionLessThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanOrEqualsExpression) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) ArithmeticSubtractExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticSubtractExpression) SoundsLikeExpression(com.alibaba.cobar.parser.ast.expression.string.SoundsLikeExpression) ArithmeticIntegerDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticIntegerDivideExpression) CollateExpression(com.alibaba.cobar.parser.ast.expression.type.CollateExpression) LogicalNotExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalNotExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression) AssignmentExpression(com.alibaba.cobar.parser.ast.expression.misc.AssignmentExpression) CaseWhenOperatorExpression(com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression) LogicalXORExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalXORExpression) UserExpression(com.alibaba.cobar.parser.ast.expression.misc.UserExpression) ArithmeticAddExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticAddExpression) ComparisionNotEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNotEqualsExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) ComparisionLessThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanExpression) ArithmeticModExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticModExpression) ArithmeticDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticDivideExpression) ComparisionGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) SoundsLikeExpression(com.alibaba.cobar.parser.ast.expression.string.SoundsLikeExpression) RegexpExpression(com.alibaba.cobar.parser.ast.expression.string.RegexpExpression) ComparisionNotEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNotEqualsExpression)

Example 2 with ComparisionLessOrGreaterThanExpression

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

the class MySQLExprParserTest method testComparision.

public void testComparision() throws Exception {
    String sql = "a  betwEen b and c Not between d and e";
    MySQLExprParser parser = new MySQLExprParser(new MySQLLexer(sql));
    Expression expr = parser.expression();
    String output = output2MySQL(expr, sql);
    Assert.assertEquals("a BETWEEN b AND c NOT BETWEEN d AND e", output);
    BetweenAndExpression ba = (BetweenAndExpression) expr;
    Assert.assertEquals("a", ((Identifier) ba.getFirst()).getIdText());
    Assert.assertEquals("b", ((Identifier) ba.getSecond()).getIdText());
    Assert.assertEquals(false, ba.isNot());
    ba = (BetweenAndExpression) ba.getThird();
    Assert.assertEquals("c", ((Identifier) ba.getFirst()).getIdText());
    Assert.assertEquals("d", ((Identifier) ba.getSecond()).getIdText());
    Assert.assertEquals("e", ((Identifier) ba.getThird()).getIdText());
    Assert.assertEquals(true, ba.isNot());
    sql = "a between b between c and d and e between f and g";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("a BETWEEN b BETWEEN c AND d AND e BETWEEN f AND g", output);
    ba = (BetweenAndExpression) expr;
    BetweenAndExpression ba2 = (BetweenAndExpression) ba.getSecond();
    BetweenAndExpression ba3 = (BetweenAndExpression) ba.getThird();
    Assert.assertEquals("a", ((Identifier) ba.getFirst()).getIdText());
    Assert.assertEquals("b", ((Identifier) ba2.getFirst()).getIdText());
    Assert.assertEquals("c", ((Identifier) ba2.getSecond()).getIdText());
    Assert.assertEquals("d", ((Identifier) ba2.getThird()).getIdText());
    Assert.assertEquals("e", ((Identifier) ba3.getFirst()).getIdText());
    Assert.assertEquals("f", ((Identifier) ba3.getSecond()).getIdText());
    Assert.assertEquals("g", ((Identifier) ba3.getThird()).getIdText());
    sql = "((select a)) between (select b)   and (select d) ";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("(SELECT a) BETWEEN (SELECT b) AND (SELECT d)", output);
    sql = "a  rliKe b not REGEXP c";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("a REGEXP b NOT REGEXP c", output);
    RegexpExpression re = (RegexpExpression) expr;
    RegexpExpression re2 = (RegexpExpression) re.getLeftOprand();
    Assert.assertEquals("a", ((Identifier) re2.getLeftOprand()).getIdText());
    Assert.assertEquals("b", ((Identifier) re2.getRightOprand()).getIdText());
    Assert.assertEquals("c", ((Identifier) re.getRightOprand()).getIdText());
    Assert.assertEquals(true, re.isNot());
    Assert.assertEquals(false, re2.isNot());
    sql = "((a)) like (((b)))escape (((d)))";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("a LIKE b ESCAPE d", output);
    sql = "((select a)) like (((select b)))escape (((select d)))";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("(SELECT a) LIKE (SELECT b) ESCAPE (SELECT d)", output);
    sql = "a  like b NOT LIKE c escape d";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("a LIKE b NOT LIKE c ESCAPE d", output);
    LikeExpression le = (LikeExpression) expr;
    LikeExpression le2 = (LikeExpression) le.getFirst();
    Assert.assertEquals("a", ((Identifier) le2.getFirst()).getIdText());
    Assert.assertEquals("b", ((Identifier) le2.getSecond()).getIdText());
    Assert.assertEquals("c", ((Identifier) le.getSecond()).getIdText());
    Assert.assertEquals("d", ((Identifier) le.getThird()).getIdText());
    Assert.assertEquals(true, le.isNot());
    Assert.assertEquals(false, le2.isNot());
    sql = "b NOT LIKE c ";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("b NOT LIKE c", output);
    sql = "a in (b) not in (select id from t1)";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("a IN (b) NOT IN (SELECT id FROM t1)", output);
    InExpression in = (InExpression) expr;
    InExpression in2 = (InExpression) in.getLeftOprand();
    Assert.assertEquals("a", ((Identifier) in2.getLeftOprand()).getIdText());
    Assert.assertTrue(QueryExpression.class.isAssignableFrom(in.getRightOprand().getClass()));
    Assert.assertEquals(true, in.isNot());
    Assert.assertEquals(false, in2.isNot());
    sql = "(select a)is not null";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("(SELECT a) IS NOT NULL", output);
    sql = "a is not null is not false is not true is not UNKNOWn is null is false is true is unknown";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("a IS NOT NULL IS NOT FALSE IS NOT TRUE IS NOT UNKNOWN IS NULL IS FALSE IS TRUE IS UNKNOWN", output);
    ComparisionIsExpression is = (ComparisionIsExpression) expr;
    ComparisionIsExpression is2 = (ComparisionIsExpression) is.getOperand();
    ComparisionIsExpression is3 = (ComparisionIsExpression) is2.getOperand();
    ComparisionIsExpression is4 = (ComparisionIsExpression) is3.getOperand();
    ComparisionIsExpression is5 = (ComparisionIsExpression) is4.getOperand();
    ComparisionIsExpression is6 = (ComparisionIsExpression) is5.getOperand();
    ComparisionIsExpression is7 = (ComparisionIsExpression) is6.getOperand();
    ComparisionIsExpression is8 = (ComparisionIsExpression) is7.getOperand();
    Assert.assertEquals(ComparisionIsExpression.IS_UNKNOWN, is.getMode());
    Assert.assertEquals(ComparisionIsExpression.IS_TRUE, is2.getMode());
    Assert.assertEquals(ComparisionIsExpression.IS_FALSE, is3.getMode());
    Assert.assertEquals(ComparisionIsExpression.IS_NULL, is4.getMode());
    Assert.assertEquals(ComparisionIsExpression.IS_NOT_UNKNOWN, is5.getMode());
    Assert.assertEquals(ComparisionIsExpression.IS_NOT_TRUE, is6.getMode());
    Assert.assertEquals(ComparisionIsExpression.IS_NOT_FALSE, is7.getMode());
    Assert.assertEquals(ComparisionIsExpression.IS_NOT_NULL, is8.getMode());
    Assert.assertEquals("a", ((Identifier) is8.getOperand()).getIdText());
    sql = "a = b <=> c >= d > e <= f < g <> h != i";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("a = b <=> c >= d > e <= f < g <> h != i", output);
    ComparisionNotEqualsExpression neq = (ComparisionNotEqualsExpression) expr;
    ComparisionLessOrGreaterThanExpression lg = (ComparisionLessOrGreaterThanExpression) neq.getLeftOprand();
    ComparisionLessThanExpression l = (ComparisionLessThanExpression) lg.getLeftOprand();
    ComparisionLessThanOrEqualsExpression leq = (ComparisionLessThanOrEqualsExpression) l.getLeftOprand();
    ComparisionGreaterThanExpression g = (ComparisionGreaterThanExpression) leq.getLeftOprand();
    ComparisionGreaterThanOrEqualsExpression geq = (ComparisionGreaterThanOrEqualsExpression) g.getLeftOprand();
    ComparisionNullSafeEqualsExpression nseq = (ComparisionNullSafeEqualsExpression) geq.getLeftOprand();
    ComparisionEqualsExpression eq = (ComparisionEqualsExpression) nseq.getLeftOprand();
    Assert.assertEquals("i", ((Identifier) neq.getRightOprand()).getIdText());
    Assert.assertEquals("h", ((Identifier) lg.getRightOprand()).getIdText());
    Assert.assertEquals("g", ((Identifier) l.getRightOprand()).getIdText());
    Assert.assertEquals("f", ((Identifier) leq.getRightOprand()).getIdText());
    Assert.assertEquals("e", ((Identifier) g.getRightOprand()).getIdText());
    Assert.assertEquals("d", ((Identifier) geq.getRightOprand()).getIdText());
    Assert.assertEquals("c", ((Identifier) nseq.getRightOprand()).getIdText());
    Assert.assertEquals("b", ((Identifier) eq.getRightOprand()).getIdText());
    Assert.assertEquals("a", ((Identifier) eq.getLeftOprand()).getIdText());
    sql = "a sounds like b sounds like c";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("a SOUNDS LIKE b SOUNDS LIKE c", output);
    SoundsLikeExpression sl = (SoundsLikeExpression) expr;
    SoundsLikeExpression sl2 = (SoundsLikeExpression) sl.getLeftOprand();
    Assert.assertEquals("a", ((Identifier) sl2.getLeftOprand()).getIdText());
    Assert.assertEquals("b", ((Identifier) sl2.getRightOprand()).getIdText());
    Assert.assertEquals("c", ((Identifier) sl.getRightOprand()).getIdText());
    sql = "a like b escape c";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("a LIKE b ESCAPE c", output);
    sql = "(select a) collate z";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("(SELECT a) COLLATE z", output);
    sql = "val1 IN (1,2,'a')";
    parser = new MySQLExprParser(new MySQLLexer(sql));
    expr = parser.expression();
    output = output2MySQL(expr, sql);
    Assert.assertEquals("val1 IN (1, 2, 'a')", output);
}
Also used : ComparisionGreaterThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanOrEqualsExpression) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) ComparisionLessThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanOrEqualsExpression) ComparisionLessThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanExpression) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) MySQLLexer(com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) SoundsLikeExpression(com.alibaba.cobar.parser.ast.expression.string.SoundsLikeExpression) ComparisionLessOrGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessOrGreaterThanExpression) RegexpExpression(com.alibaba.cobar.parser.ast.expression.string.RegexpExpression) LogicalAndExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression) UnaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression) MinusExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.MinusExpression) ArithmeticMultiplyExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticMultiplyExpression) ComparisionLessThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanOrEqualsExpression) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) TernaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.TernaryOperatorExpression) ArithmeticSubtractExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticSubtractExpression) BitAndExpression(com.alibaba.cobar.parser.ast.expression.bit.BitAndExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) NegativeValueExpression(com.alibaba.cobar.parser.ast.expression.logical.NegativeValueExpression) SoundsLikeExpression(com.alibaba.cobar.parser.ast.expression.string.SoundsLikeExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) CastBinaryExpression(com.alibaba.cobar.parser.ast.expression.type.CastBinaryExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) ArithmeticIntegerDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticIntegerDivideExpression) CollateExpression(com.alibaba.cobar.parser.ast.expression.type.CollateExpression) BitInvertExpression(com.alibaba.cobar.parser.ast.expression.bit.BitInvertExpression) BitXORExpression(com.alibaba.cobar.parser.ast.expression.bit.BitXORExpression) LogicalNotExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalNotExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression) BitShiftExpression(com.alibaba.cobar.parser.ast.expression.bit.BitShiftExpression) AssignmentExpression(com.alibaba.cobar.parser.ast.expression.misc.AssignmentExpression) CaseWhenOperatorExpression(com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression) BitOrExpression(com.alibaba.cobar.parser.ast.expression.bit.BitOrExpression) ComparisionGreaterThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanOrEqualsExpression) LogicalXORExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalXORExpression) UserExpression(com.alibaba.cobar.parser.ast.expression.misc.UserExpression) ArithmeticAddExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticAddExpression) PolyadicOperatorExpression(com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression) ComparisionNotEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNotEqualsExpression) BinaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) LogicalOrExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression) ComparisionLessThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanExpression) ArithmeticModExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticModExpression) ComparisionGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanExpression) ArithmeticDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticDivideExpression) ComparisionLessOrGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessOrGreaterThanExpression) ComparisionGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) SoundsLikeExpression(com.alibaba.cobar.parser.ast.expression.string.SoundsLikeExpression) RegexpExpression(com.alibaba.cobar.parser.ast.expression.string.RegexpExpression) ComparisionNotEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNotEqualsExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)

Aggregations

Expression (com.alibaba.cobar.parser.ast.expression.Expression)2 ArithmeticAddExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticAddExpression)2 ArithmeticDivideExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticDivideExpression)2 ArithmeticIntegerDivideExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticIntegerDivideExpression)2 ArithmeticModExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticModExpression)2 ArithmeticMultiplyExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticMultiplyExpression)2 ArithmeticSubtractExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticSubtractExpression)2 MinusExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.MinusExpression)2 BitAndExpression (com.alibaba.cobar.parser.ast.expression.bit.BitAndExpression)2 BitInvertExpression (com.alibaba.cobar.parser.ast.expression.bit.BitInvertExpression)2 BitOrExpression (com.alibaba.cobar.parser.ast.expression.bit.BitOrExpression)2 BitShiftExpression (com.alibaba.cobar.parser.ast.expression.bit.BitShiftExpression)2 BitXORExpression (com.alibaba.cobar.parser.ast.expression.bit.BitXORExpression)2 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)2 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)2 ComparisionGreaterThanExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanExpression)2 ComparisionGreaterThanOrEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanOrEqualsExpression)2 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)2 ComparisionLessOrGreaterThanExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessOrGreaterThanExpression)2 ComparisionLessThanExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanExpression)2