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;
}
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());
}
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);
}
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;
}
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());
}
Aggregations