Search in sources :

Example 11 with CompareCriteria

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

the class TestSearchedCaseExpression method getWhenCriteria.

public static List getWhenCriteria(int criteria) {
    ArrayList list = new ArrayList();
    // $NON-NLS-1$
    ElementSymbol x = new ElementSymbol("x");
    for (int i = 0; i < criteria; i++) {
        list.add(new CompareCriteria(x, CompareCriteria.EQ, new Constant(new Integer(i))));
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 12 with CompareCriteria

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

the class TestSearchedCaseExpression method testClone.

/*
     * Test for Object clone()
     */
public void testClone() {
    // $NON-NLS-1$
    CompareCriteria c1 = new CompareCriteria(new ElementSymbol("abc"), CompareCriteria.EQ, new Constant(new Integer(20000)));
    // $NON-NLS-1$
    CompareCriteria c2 = new CompareCriteria(new ElementSymbol("xyz"), CompareCriteria.EQ, new Constant(new Integer(30000)));
    ArrayList whens = new ArrayList();
    whens.add(c1);
    whens.add(c2);
    // $NON-NLS-1$
    Constant const1 = new Constant("a");
    // $NON-NLS-1$
    Constant const2 = new Constant("b");
    ArrayList thens = new ArrayList();
    thens.add(const1);
    thens.add(const2);
    // $NON-NLS-1$
    Expression elseExpression = new Constant("c");
    SearchedCaseExpression expr = new SearchedCaseExpression(whens, thens);
    expr.setElseExpression(elseExpression);
    expr.setType(DataTypeManager.DefaultDataClasses.STRING);
    SearchedCaseExpression clone = (SearchedCaseExpression) expr.clone();
    assertTrue(expr != clone);
    assertEquals(2, clone.getWhenCount());
    TestCaseExpression.helpTestStrictEquivalence(c1, clone.getWhenCriteria(0));
    TestCaseExpression.helpTestStrictEquivalence(expr.getWhenCriteria(0), clone.getWhenCriteria(0));
    TestCaseExpression.helpTestStrictEquivalence(c2, clone.getWhenCriteria(1));
    TestCaseExpression.helpTestStrictEquivalence(expr.getWhenCriteria(1), clone.getWhenCriteria(1));
    TestCaseExpression.helpTestStrictEquivalence(const1, clone.getThenExpression(0));
    TestCaseExpression.helpTestStrictEquivalence(expr.getThenExpression(0), clone.getThenExpression(0));
    TestCaseExpression.helpTestStrictEquivalence(const2, clone.getThenExpression(1));
    TestCaseExpression.helpTestStrictEquivalence(expr.getThenExpression(1), clone.getThenExpression(1));
    TestCaseExpression.helpTestStrictEquivalence(expr.getElseExpression(), clone.getElseExpression());
    assertEquals(expr.getType(), clone.getType());
}
Also used : ArrayList(java.util.ArrayList) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 13 with CompareCriteria

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

the class TestExpressionMappingVisitor method testCompareCriteria1.

@Test
public void testCompareCriteria1() {
    // $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(e1, CompareCriteria.EQ, new Constant("xyz"));
    // $NON-NLS-1$
    CompareCriteria after = new CompareCriteria(f, CompareCriteria.EQ, new Constant("xyz"));
    helpTest(before, map, after);
}
Also used : HashMap(java.util.HashMap) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Test(org.junit.Test)

Example 14 with CompareCriteria

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

the class TestJoinPredicate method example.

// ################################## TEST HELPERS ################################
/**
 * Constructs an example <code>JoinPredicate</code> object that can be used
 * as join predicate in a query.
 *
 * @param joinType the type of join to be constructed
 * @param joinOnElement the element name to be used in the left and right
 * 						side criteria of the ON expression of the join
 * @return a join predicate object
 */
public static JoinPredicate example(JoinType joinType, String joinOnElement) {
    JoinPredicate jp = new JoinPredicate();
    // $NON-NLS-1$
    GroupSymbol g1 = new GroupSymbol("m.g1");
    // $NON-NLS-1$
    GroupSymbol g2 = new GroupSymbol("m.g2");
    FromClause lc = new UnaryFromClause(g1);
    FromClause rc = new UnaryFromClause(g2);
    // $NON-NLS-1$
    Expression le = new ElementSymbol("m.g1." + joinOnElement);
    // $NON-NLS-1$
    Expression re = new ElementSymbol("m.g2." + joinOnElement);
    Criteria c1 = new CompareCriteria(le, CompareCriteria.EQ, re);
    jp.setLeftClause(lc);
    jp.setRightClause(rc);
    jp.setJoinType(joinType != null ? joinType : JoinType.JOIN_LEFT_OUTER);
    jp.setJoinCriteria(Arrays.asList(new Object[] { c1 }));
    return jp;
}
Also used : FromClause(org.teiid.query.sql.lang.FromClause) UnaryFromClause(org.teiid.query.sql.lang.UnaryFromClause) UnaryFromClause(org.teiid.query.sql.lang.UnaryFromClause) JoinPredicate(org.teiid.query.sql.lang.JoinPredicate) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 15 with CompareCriteria

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

the class TestDependentCriteriaProcessor method testSetCriteria.

@Test
public void testSetCriteria() throws Exception {
    DependentAccessNode dan = new DependentAccessNode(0);
    // $NON-NLS-1$
    SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), Arrays.asList(new Constant(1), new Constant(2)));
    sc.setAllConstants(true);
    DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, -1, dan, sc);
    Criteria result = dcp.prepareCriteria();
    // $NON-NLS-1$
    assertEquals(new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(1)), result);
    assertTrue(dcp.hasNextCommand());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) SetCriteria(org.teiid.query.sql.lang.SetCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SetCriteria(org.teiid.query.sql.lang.SetCriteria) Criteria(org.teiid.query.sql.lang.Criteria) 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