Search in sources :

Example 46 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestStaticSymbolMappingVisitor method testVisitUpdate2.

public void testVisitUpdate2() {
    Update update = new Update();
    update.setGroup(exampleGroup(true, 0));
    // $NON-NLS-1$
    update.addChange(exampleElement(true, 0), new Constant("abc"));
    // $NON-NLS-1$
    update.addChange(exampleElement(true, 1), new Constant("abc"));
    // $NON-NLS-1$
    update.setCriteria(new CompareCriteria(exampleElement(true, 2), CompareCriteria.LT, new Constant("xyz")));
    helpTest(update, getSymbolMap());
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) Update(org.teiid.query.sql.lang.Update) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 47 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestStaticSymbolMappingVisitor method testVisitCompareCriteria.

// ################################## ACTUAL TESTS ################################
public void testVisitCompareCriteria() {
    CompareCriteria cc = new CompareCriteria(exampleElement(true, 0), CompareCriteria.EQ, exampleElement(true, 1));
    helpTest(cc, getSymbolMap());
}
Also used : CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 48 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestSearchedCaseExpression method testSetWhen.

public void testSetWhen() {
    SearchedCaseExpression caseExpr = example(4);
    // Both are nulls
    try {
        caseExpr.setWhen(null, null);
        // $NON-NLS-1$
        fail("Setting WHEN and THEN to null should have failed.");
    } catch (IllegalArgumentException e) {
        // There should be no side-effects of an illegal argument
        helpTestWhenCriteria(caseExpr, 4);
        TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
    }
    try {
        caseExpr.setWhen(getWhenCriteria(2), null);
        // $NON-NLS-1$
        fail("Setting THEN to null should have failed.");
    } catch (IllegalArgumentException e) {
        // There should be no side-effects of an illegal argument
        helpTestWhenCriteria(caseExpr, 4);
        TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
    }
    try {
        caseExpr.setWhen(null, TestCaseExpression.getThenExpressions(2));
        // $NON-NLS-1$
        fail("Setting WHEN to null should have failed.");
    } catch (IllegalArgumentException e) {
        // There should be no side-effects of an illegal argument
        helpTestWhenCriteria(caseExpr, 4);
        TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
    }
    try {
        caseExpr.setWhen(getWhenCriteria(0), TestCaseExpression.getThenExpressions(0));
        // $NON-NLS-1$
        fail("Setting WHEN and THEN to empty lists should have failed.");
    } catch (IllegalArgumentException e) {
        // There should be no side-effects of an illegal argument
        helpTestWhenCriteria(caseExpr, 4);
        TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
    }
    try {
        caseExpr.setWhen(TestCaseExpression.getWhenExpressions(3), TestCaseExpression.getThenExpressions(3));
        // $NON-NLS-1$
        fail("Setting WHEN non Criteria types should have failed.");
    } catch (IllegalArgumentException e) {
        // There should be no side-effects of an illegal argument
        helpTestWhenCriteria(caseExpr, 4);
        TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
    }
    caseExpr.setWhen(getWhenCriteria(3), getWhenCriteria(3));
    ArrayList whens = new ArrayList();
    // $NON-NLS-1$
    whens.add(new CompareCriteria(new ElementSymbol("abc"), CompareCriteria.EQ, new Constant(new Integer(20000))));
    // $NON-NLS-1$
    whens.add(new CompareCriteria(new ElementSymbol("xyz"), CompareCriteria.EQ, new Constant(new Integer(30000))));
    ArrayList thens = new ArrayList();
    thens.add(new Constant(new Integer(20000)));
    thens.add(new Constant(new Integer(30000)));
    caseExpr.setWhen(whens, thens);
    assertEquals(2, caseExpr.getWhenCount());
    // $NON-NLS-1$
    assertEquals(new CompareCriteria(new ElementSymbol("abc"), CompareCriteria.EQ, new Constant(new Integer(20000))), caseExpr.getWhenCriteria(0));
    // $NON-NLS-1$
    assertEquals(new CompareCriteria(new ElementSymbol("xyz"), CompareCriteria.EQ, new Constant(new Integer(30000))), caseExpr.getWhenCriteria(1));
    assertEquals(new Constant(new Integer(20000)), caseExpr.getThenExpression(0));
    assertEquals(new Constant(new Integer(30000)), caseExpr.getThenExpression(1));
}
Also used : ArrayList(java.util.ArrayList) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 49 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestExpressionMappingVisitor method testCompareCriteria2.

@Test
public void testCompareCriteria2() {
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("e1");
    // $NON-NLS-1$
    Function f = new Function("+", new Expression[] { new Constant(new Integer(2)), new Constant(new Integer(5)) });
    Map<Expression, Expression> map = new HashMap<Expression, Expression>();
    map.put(e1, f);
    // $NON-NLS-1$
    CompareCriteria before = new CompareCriteria(new Constant("xyz"), CompareCriteria.EQ, e1);
    // $NON-NLS-1$
    CompareCriteria after = new CompareCriteria(new Constant("xyz"), CompareCriteria.EQ, f);
    helpTest(before, map, after);
}
Also used : HashMap(java.util.HashMap) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Test(org.junit.Test)

Example 50 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestExpressionMappingVisitor method testCaseExpression2.

@Test
public void testCaseExpression2() {
    // $NON-NLS-1$
    ElementSymbol x = new ElementSymbol("x");
    // $NON-NLS-1$
    ElementSymbol y = new ElementSymbol("y");
    HashMap<Expression, Expression> map = new HashMap<Expression, Expression>();
    map.put(x, y);
    ArrayList<Expression> whens = new ArrayList<Expression>(), thens = new ArrayList<Expression>();
    whens.add(new CompareCriteria(y, CompareCriteria.EQ, new Constant(new Integer(0))));
    thens.add(new Constant(new Integer(0)));
    whens.add(new CompareCriteria(y, CompareCriteria.EQ, new Constant(new Integer(1))));
    thens.add(new Constant(new Integer(1)));
    whens.add(new CompareCriteria(y, CompareCriteria.EQ, new Constant(new Integer(2))));
    thens.add(new Constant(new Integer(2)));
    SearchedCaseExpression mapped = new SearchedCaseExpression(whens, thens);
    mapped.setElseExpression(new Constant(new Integer(9999)));
    helpTest(TestSearchedCaseExpression.example(3), map, mapped);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Test(org.junit.Test)

Aggregations

CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)52 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)25 Constant (org.teiid.query.sql.symbol.Constant)24 Criteria (org.teiid.query.sql.lang.Criteria)21 ArrayList (java.util.ArrayList)15 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)11 Test (org.junit.Test)10 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)9 CompoundCriteria (org.teiid.query.sql.lang.CompoundCriteria)9 Expression (org.teiid.query.sql.symbol.Expression)9 IsNullCriteria (org.teiid.query.sql.lang.IsNullCriteria)8 List (java.util.List)7 HashMap (java.util.HashMap)6 Query (org.teiid.query.sql.lang.Query)6 SetCriteria (org.teiid.query.sql.lang.SetCriteria)6 From (org.teiid.query.sql.lang.From)5 Select (org.teiid.query.sql.lang.Select)5 DependentSetCriteria (org.teiid.query.sql.lang.DependentSetCriteria)4 Collection (java.util.Collection)3 JoinType (org.teiid.query.sql.lang.JoinType)3