Search in sources :

Example 41 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestSelectNode method testEmptyBatchIndexing.

/**
 * Ensures that a final empty batch is reindexed so that the batch iterator works correctly
 */
@Test
public void testEmptyBatchIndexing() 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(new Constant(0), CompareCriteria.EQ, new Constant(new Integer(1)));
    List childElements = new ArrayList();
    childElements.add(es1);
    RelationalNode child = new RelationalNode(0) {

        int i = 0;

        @Override
        public Object clone() {
            return null;
        }

        @Override
        protected TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
            if (i++ == 0) {
                return new TupleBatch(1, new List[] { Arrays.asList(1), Arrays.asList(1) });
            }
            TupleBatch batch = new TupleBatch(3, new List[0]);
            batch.setTerminationFlag(true);
            return batch;
        }
    };
    helpTestSelect(elements, crit, childElements, null, new List[0], child);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Example 42 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestSelectNode method testSelectWithLookup.

@Test
public void testSelectWithLookup() throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es2 = new ElementSymbol("e2");
    es2.setType(DataTypeManager.DefaultDataClasses.STRING);
    List elements = new ArrayList();
    elements.add(es1);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), es1 });
    // $NON-NLS-1$
    FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class });
    func.setFunctionDescriptor(desc);
    func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    CompareCriteria crit = new CompareCriteria(func, CompareCriteria.EQ, new Constant(new Integer(1)));
    List[] data = new List[20];
    for (int i = 0; i < 20; i++) {
        data[i] = new ArrayList();
        data[i].add(new Integer((i * 51) % 11));
        // $NON-NLS-1$
        String str = "" + (i * 3);
        str = str.substring(0, 1);
        data[i].add(str);
    }
    List childElements = new ArrayList();
    childElements.add(es1);
    childElements.add(es2);
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(0) }), Arrays.asList(new Object[] { new Integer(0) }) };
    FakeDataManager dataMgr = new FakeDataManager();
    dataMgr.setThrowBlocked(true);
    Map valueMap = new HashMap();
    valueMap.put(new Integer(0), new Integer(1));
    valueMap.put(new Integer(1), new Integer(2));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    dataMgr.defineCodeTable("pm1.g1", "e1", "e2", valueMap);
    helpTestSelect(elements, crit, data, childElements, dataMgr, expected);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) FakeDataManager(org.teiid.query.processor.FakeDataManager) HashMap(java.util.HashMap) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Function(org.teiid.query.sql.symbol.Function) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 43 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestSelectNode method testSimpleSelect.

@Test
public void testSimpleSelect() throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es2 = new ElementSymbol("e2");
    es2.setType(DataTypeManager.DefaultDataClasses.STRING);
    List elements = new ArrayList();
    elements.add(es1);
    CompareCriteria crit = new CompareCriteria(es1, CompareCriteria.EQ, new Constant(new Integer(1)));
    List[] data = new List[20];
    for (int i = 0; i < 20; i++) {
        data[i] = new ArrayList();
        data[i].add(new Integer((i * 51) % 11));
        // $NON-NLS-1$
        String str = "" + (i * 3);
        str = str.substring(0, 1);
        data[i].add(str);
    }
    List childElements = new ArrayList();
    childElements.add(es1);
    childElements.add(es2);
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }), Arrays.asList(new Object[] { new Integer(1) }) };
    helpTestSelect(elements, crit, data, childElements, null, expected);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Test(org.junit.Test)

Example 44 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestSelectNode method testNoRows.

@Test
public void testNoRows() throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es2 = new ElementSymbol("e2");
    es2.setType(DataTypeManager.DefaultDataClasses.STRING);
    List elements = new ArrayList();
    elements.add(es1);
    List[] data = new List[0];
    CompareCriteria crit = new CompareCriteria(es1, CompareCriteria.EQ, new Constant(new Integer(1)));
    List childElements = new ArrayList();
    childElements.add(es1);
    childElements.add(es2);
    helpTestSelect(elements, crit, data, childElements, null, data);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Test(org.junit.Test)

Example 45 with CompareCriteria

use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.

the class TestCompoundCriteria method testClone1.

public void testClone1() {
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("e1");
    // $NON-NLS-1$
    CompareCriteria ccrit1 = new CompareCriteria(e1, CompareCriteria.EQ, new Constant("abc"));
    // $NON-NLS-1$
    ElementSymbol e2 = new ElementSymbol("e2");
    // $NON-NLS-1$
    CompareCriteria ccrit2 = new CompareCriteria(e2, CompareCriteria.EQ, new Constant("xyz"));
    CompoundCriteria comp = new CompoundCriteria(CompoundCriteria.AND, ccrit1, ccrit2);
    UnitTestUtil.helpTestEquivalence(0, comp, comp.clone());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Aggregations

CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)52 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)25 Constant (org.teiid.query.sql.symbol.Constant)24 Criteria (org.teiid.query.sql.lang.Criteria)21 ArrayList (java.util.ArrayList)15 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)11 Test (org.junit.Test)10 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)9 CompoundCriteria (org.teiid.query.sql.lang.CompoundCriteria)9 Expression (org.teiid.query.sql.symbol.Expression)9 IsNullCriteria (org.teiid.query.sql.lang.IsNullCriteria)8 List (java.util.List)7 HashMap (java.util.HashMap)6 Query (org.teiid.query.sql.lang.Query)6 SetCriteria (org.teiid.query.sql.lang.SetCriteria)6 From (org.teiid.query.sql.lang.From)5 Select (org.teiid.query.sql.lang.Select)5 DependentSetCriteria (org.teiid.query.sql.lang.DependentSetCriteria)4 Collection (java.util.Collection)3 JoinType (org.teiid.query.sql.lang.JoinType)3