Search in sources :

Example 1 with SetCriteria

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());
}
Also used : In(org.teiid.language.In) SetCriteria(org.teiid.query.sql.lang.SetCriteria) AndOr(org.teiid.language.AndOr) Test(org.junit.Test)

Example 2 with SetCriteria

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());
}
Also used : SetCriteria(org.teiid.query.sql.lang.SetCriteria) AndOr(org.teiid.language.AndOr) Test(org.junit.Test)

Example 3 with SetCriteria

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;
}
Also used : Expression(org.teiid.language.Expression) SetCriteria(org.teiid.query.sql.lang.SetCriteria) ArrayList(java.util.ArrayList)

Example 4 with SetCriteria

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);
}
Also used : DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) Constant(org.teiid.query.sql.symbol.Constant) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) AbstractSetCriteria(org.teiid.query.sql.lang.AbstractSetCriteria) SetCriteria(org.teiid.query.sql.lang.SetCriteria) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) Criteria(org.teiid.query.sql.lang.Criteria) DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) AbstractSetCriteria(org.teiid.query.sql.lang.AbstractSetCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SetCriteria(org.teiid.query.sql.lang.SetCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 5 with SetCriteria

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());
}
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) Test(org.junit.Test)

Aggregations

SetCriteria (org.teiid.query.sql.lang.SetCriteria)12 Criteria (org.teiid.query.sql.lang.Criteria)8 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)7 Test (org.junit.Test)6 Constant (org.teiid.query.sql.symbol.Constant)6 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 AndOr (org.teiid.language.AndOr)2 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)2 CompoundCriteria (org.teiid.query.sql.lang.CompoundCriteria)2 DependentSetCriteria (org.teiid.query.sql.lang.DependentSetCriteria)2 IsNullCriteria (org.teiid.query.sql.lang.IsNullCriteria)2 Expression (org.teiid.query.sql.symbol.Expression)2 Reference (org.teiid.query.sql.symbol.Reference)2 HashMap (java.util.HashMap)1 Expression (org.teiid.language.Expression)1 In (org.teiid.language.In)1 LanguageObject (org.teiid.query.sql.LanguageObject)1 LanguageVisitor (org.teiid.query.sql.LanguageVisitor)1