Search in sources :

Example 16 with TupleBuffer

use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.

the class TestJoinNode method helpCreateJoin.

protected void helpCreateJoin() {
    // $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.INTEGER);
    List leftElements = new ArrayList();
    leftElements.add(es1);
    leftNode = new BlockingFakeRelationalNode(1, leftTuples);
    leftNode.setElements(leftElements);
    List rightElements = new ArrayList();
    rightElements.add(es2);
    rightNode = new BlockingFakeRelationalNode(2, rightTuples) {

        @Override
        public boolean hasBuffer() {
            return false;
        }

        @Override
        public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
            fail();
            throw new AssertionError();
        }
    };
    rightNode.setElements(rightElements);
    List joinElements = new ArrayList();
    joinElements.add(es1);
    joinElements.add(es2);
    join = new JoinNode(3);
    joinStrategy = new NestedLoopJoinStrategy();
    join.setJoinStrategy(joinStrategy);
    join.setElements(joinElements);
    join.setJoinType(joinType);
    switch(criteriaType) {
        case NO_CRITERIA:
            break;
        case EQUAL_CRITERIA:
            join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es2));
            joinStrategy = new MergeJoinStrategy(SortOption.SORT, SortOption.SORT, false);
            join.setJoinStrategy(joinStrategy);
            break;
        case FUNCTION_CRITERIA:
            // $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 joinCriteria = new CompareCriteria(es2, CompareCriteria.EQ, func);
            join.setJoinCriteria(joinCriteria);
            break;
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) TupleBuffer(org.teiid.common.buffer.TupleBuffer) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) BlockedException(org.teiid.common.buffer.BlockedException) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Function(org.teiid.query.sql.symbol.Function) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 17 with TupleBuffer

use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.

the class TestSortNode method testOnePass.

@Test
public void testOnePass() throws Exception {
    // $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.INTEGER);
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$
    TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es2), "test", TupleSourceType.PROCESSOR);
    tsid.addTuple(Arrays.asList(1, 1));
    tsid.addTuple(Arrays.asList(1, 2));
    tsid.close();
    // $NON-NLS-1$
    SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema());
    List<TupleBuffer> buffers = su.onePassSort(true);
    assertEquals(1, buffers.size());
    assertTrue(!buffers.get(0).isForwardOnly());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 18 with TupleBuffer

use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.

the class TestBatchIterator method testDisableSave.

@Test
public void testDisableSave() throws Exception {
    BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) }, 2));
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER)), "test", TupleSourceType.PROCESSOR);
    // $NON-NLS-1$
    bi.setBuffer(tb, false);
    bi.setPosition(2);
    assertTrue(bi.hasNext());
    tb.setForwardOnly(true);
    bi.setPosition(1);
    bi.disableSave();
    for (int i = 0; i < 6; i++) {
        assertNotNull(bi.nextTuple());
    }
    assertNull(bi.nextTuple());
    assertEquals(0, tb.getManagedRowCount());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) List(java.util.List) FakeRelationalNode(org.teiid.query.processor.relational.FakeRelationalNode) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 19 with TupleBuffer

use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.

the class TestBatchIterator method testReset1.

@Test
public void testReset1() throws Exception {
    BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(2), Arrays.asList(3) }, 2));
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER)), "test", TupleSourceType.PROCESSOR);
    // $NON-NLS-1$
    bi.setBuffer(tb, true);
    bi.nextTuple();
    bi.mark();
    bi.nextTuple();
    bi.reset();
    assertEquals(2, bi.getCurrentIndex());
    assertEquals(2, bi.nextTuple().get(0));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) List(java.util.List) FakeRelationalNode(org.teiid.query.processor.relational.FakeRelationalNode) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 20 with TupleBuffer

use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.

the class TestBatchIterator method testReset2.

@Test
public void testReset2() throws Exception {
    BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(2) }, 2));
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER)), "test", TupleSourceType.PROCESSOR);
    // $NON-NLS-1$
    bi.setBuffer(tb, true);
    bi.hasNext();
    bi.mark();
    bi.nextTuple();
    bi.nextTuple();
    assertNull(bi.nextTuple());
    bi.reset();
    bi.hasNext();
    assertEquals(1, bi.getCurrentIndex());
    assertEquals(1, bi.nextTuple().get(0));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) List(java.util.List) FakeRelationalNode(org.teiid.query.processor.relational.FakeRelationalNode) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Aggregations

TupleBuffer (org.teiid.common.buffer.TupleBuffer)43 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)19 BufferManager (org.teiid.common.buffer.BufferManager)16 List (java.util.List)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)11 BlockedException (org.teiid.common.buffer.BlockedException)10 TupleSource (org.teiid.common.buffer.TupleSource)10 CommandContext (org.teiid.query.util.CommandContext)7 TeiidProcessingException (org.teiid.core.TeiidProcessingException)6 FakeRelationalNode (org.teiid.query.processor.relational.FakeRelationalNode)6 TeiidComponentException (org.teiid.core.TeiidComponentException)5 TupleBatch (org.teiid.common.buffer.TupleBatch)4 Map (java.util.Map)3 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)3 Expression (org.teiid.query.sql.symbol.Expression)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 IndexedTupleSource (org.teiid.common.buffer.IndexedTupleSource)2