use of org.teiid.query.sql.lang.Criteria in project teiid by teiid.
the class DependentCriteriaProcessor method replaceDependentCriteria.
public Criteria replaceDependentCriteria(AbstractSetCriteria crit, SetState state) throws TeiidComponentException {
if (state.overMax) {
DependentValueSource originalVs = (DependentValueSource) dependentNode.getContext().getVariableContext().getGlobalValue(((DependentSetCriteria) crit).getContextSymbol());
originalVs.setUnused(true);
return QueryRewriter.TRUE_CRITERIA;
}
if (state.replacement.isEmpty()) {
// No values - return criteria that is always false
return QueryRewriter.FALSE_CRITERIA;
}
int numberOfSets = 1;
int setSize = Integer.MAX_VALUE;
if (this.maxSetSize > 0) {
setSize = (int) Math.max(1, this.maxSetSize / state.valueCount);
numberOfSets = state.replacement.size() / setSize + (state.replacement.size() % setSize != 0 ? 1 : 0);
}
Iterator<Constant> iter = state.replacement.iterator();
ArrayList<Criteria> orCrits = new ArrayList<Criteria>(numberOfSets);
for (int i = 0; i < numberOfSets; i++) {
if (setSize == 1 || i + 1 == state.replacement.size()) {
orCrits.add(new CompareCriteria(crit.getExpression(), CompareCriteria.EQ, iter.next()));
} else {
List<Constant> vals = new ArrayList<Constant>(Math.min(state.replacement.size(), setSize));
for (int j = 0; j < setSize && iter.hasNext(); j++) {
Constant val = iter.next();
vals.add(val);
}
SetCriteria sc = new SetCriteria();
sc.setExpression(crit.getExpression());
sc.setValues(vals);
orCrits.add(sc);
}
}
if (orCrits.size() == 1) {
return orCrits.get(0);
}
return new CompoundCriteria(CompoundCriteria.OR, orCrits);
}
use of org.teiid.query.sql.lang.Criteria 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.Criteria in project teiid by teiid.
the class TestDependentCriteriaProcessor method testNegatedSetCriteria.
@Test
public void testNegatedSetCriteria() 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);
sc.negate();
DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, -1, dan, sc);
Criteria result = dcp.prepareCriteria();
assertEquals(sc, result);
assertFalse(dcp.hasNextCommand());
}
use of org.teiid.query.sql.lang.Criteria 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());
}
use of org.teiid.query.sql.lang.Criteria in project teiid by teiid.
the class TestSelectNode method testTimeslicing.
@Test
public void testTimeslicing() throws TeiidComponentException, TeiidProcessingException {
// $NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("e1");
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List elements = new ArrayList();
elements.add(es1);
CompareCriteria crit = new CompareCriteria(es1, CompareCriteria.EQ, new Constant(new Integer(1)));
List[] data = new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) };
List childElements = new ArrayList();
childElements.add(es1);
helpTestSelect(elements, crit, childElements, null, data, new FakeRelationalNode(2, data), new SelectNode(3) {
int i = 0;
@Override
protected Evaluator getEvaluator(Map elementMap) {
return new Evaluator(elementMap, getDataManager(), getContext()) {
@Override
public Boolean evaluateTVL(Criteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
if (i++ == 1) {
throw new QueryProcessor.ExpiredTimeSliceException();
}
return super.evaluateTVL(criteria, tuple);
}
};
}
});
}
Aggregations