Search in sources :

Example 1 with Criteria

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);
}
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 2 with Criteria

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;
}
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 3 with Criteria

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

Example 4 with Criteria

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

Example 5 with Criteria

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);
                }
            };
        }
    });
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Evaluator(org.teiid.query.eval.Evaluator) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) BlockedException(org.teiid.common.buffer.BlockedException) QueryProcessor(org.teiid.query.processor.QueryProcessor) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Criteria (org.teiid.query.sql.lang.Criteria)67 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)40 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)35 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)22 Expression (org.teiid.query.sql.symbol.Expression)22 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)22 CompoundCriteria (org.teiid.query.sql.lang.CompoundCriteria)19 ArrayList (java.util.ArrayList)16 List (java.util.List)15 DependentSetCriteria (org.teiid.query.sql.lang.DependentSetCriteria)13 IsNullCriteria (org.teiid.query.sql.lang.IsNullCriteria)12 Constant (org.teiid.query.sql.symbol.Constant)11 SymbolMap (org.teiid.query.sql.util.SymbolMap)11 JoinType (org.teiid.query.sql.lang.JoinType)10 SetCriteria (org.teiid.query.sql.lang.SetCriteria)10 LinkedList (java.util.LinkedList)7 Reference (org.teiid.query.sql.symbol.Reference)6 LinkedHashSet (java.util.LinkedHashSet)5 LanguageObject (org.teiid.query.sql.LanguageObject)5 Collection (java.util.Collection)4