use of org.teiid.query.sql.lang.SetCriteria in project teiid by teiid.
the class TestInCriteriaImpl method testExpansion1.
@Test
public void testExpansion1() throws Exception {
SetCriteria inCriteria = helpExample(false);
LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.example1Cached());
lbf.setMaxInPredicateSize(2);
AndOr or = (AndOr) lbf.translate(inCriteria);
assertEquals(Operator.OR, or.getOperator());
assertEquals(2, ((In) or.getRightCondition()).getRightExpressions().size());
inCriteria.setNegated(true);
AndOr and = (AndOr) lbf.translate(inCriteria);
assertEquals(Operator.AND, and.getOperator());
assertEquals("300 NOT IN (100, 200) AND 300 NOT IN (300, 400)", and.toString());
}
use of org.teiid.query.sql.lang.SetCriteria in project teiid by teiid.
the class TestInCriteriaImpl method testExpansion.
@Test
public void testExpansion() throws Exception {
SetCriteria inCriteria = helpExample(false);
LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.example1Cached());
lbf.setConvertIn(true);
AndOr or = (AndOr) lbf.translate(inCriteria);
assertEquals(Operator.OR, or.getOperator());
inCriteria.setNegated(true);
AndOr and = (AndOr) lbf.translate(inCriteria);
assertEquals(Operator.AND, and.getOperator());
}
use of org.teiid.query.sql.lang.SetCriteria in project teiid by teiid.
the class TestInCriteriaImpl method helpExample.
public static SetCriteria helpExample(boolean negated) {
ArrayList<org.teiid.query.sql.symbol.Expression> values = new ArrayList<org.teiid.query.sql.symbol.Expression>();
values.add(TestLiteralImpl.helpExample(100));
values.add(TestLiteralImpl.helpExample(200));
values.add(TestLiteralImpl.helpExample(300));
values.add(TestLiteralImpl.helpExample(400));
SetCriteria crit = new SetCriteria(TestLiteralImpl.helpExample(300), values);
crit.setNegated(negated);
return crit;
}
use of org.teiid.query.sql.lang.SetCriteria 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.SetCriteria 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());
}
Aggregations