Search in sources :

Example 36 with TupleBuffer

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

the class TestBatchIterator method testReadAheadMark.

@Test
public void testReadAheadMark() 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), 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, true);
    bi.nextTuple();
    assertEquals(1, bi.available());
    assertEquals(0, bi.getBuffer().getRowCount());
    bi.readAhead(100);
    assertEquals(4, bi.getBuffer().getRowCount());
    // shouldn't keep reading
    bi.readAhead(2);
    assertEquals(4, bi.getBuffer().getRowCount());
    bi.readAhead(5);
    assertEquals(6, bi.getBuffer().getRowCount());
    // does nothing
    bi.readAhead(8);
    for (int i = 0; i < 6; i++) {
        assertNotNull(bi.nextTuple());
    }
    assertNull(bi.nextTuple());
}
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 37 with TupleBuffer

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

the class TestBatchIterator method testReadAhead.

@Test
public void testReadAhead() 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.nextTuple();
    assertEquals(1, bi.available());
    assertEquals(2, bi.getBuffer().getRowCount());
    bi.readAhead(100);
    assertEquals(4, bi.getBuffer().getRowCount());
    // shouldn't keep reading
    bi.readAhead(3);
    assertEquals(4, bi.getBuffer().getRowCount());
    bi.readAhead(5);
    assertEquals(6, bi.getBuffer().getRowCount());
    // does nothing
    bi.readAhead(8);
    for (int i = 0; i < 5; i++) {
        assertNotNull(bi.nextTuple());
    }
    assertNull(bi.nextTuple());
}
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 38 with TupleBuffer

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

the class TestQueryProcessor method helpTestProcessor.

public void helpTestProcessor(FakeProcessorPlan plan, List[] expectedResults) throws TeiidException {
    BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
    FakeDataManager dataManager = new FakeDataManager();
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "group", null, null, 1);
    QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
    BatchCollector collector = processor.createBatchCollector();
    TupleBuffer tsID = null;
    while (true) {
        try {
            tsID = collector.collectTuples();
            break;
        } catch (BlockedException e) {
        }
    }
    // Compare # of rows in actual and expected
    // $NON-NLS-1$
    assertEquals("Did not get expected # of rows", expectedResults.length, tsID.getRowCount());
    // Compare actual with expected results
    TupleSource actual = tsID.createIndexedTupleSource();
    if (expectedResults.length > 0) {
        for (int i = 0; i < expectedResults.length; i++) {
            List actRecord = actual.nextTuple();
            List expRecord = expectedResults[i];
            // $NON-NLS-1$
            assertEquals("Did not match row at row index " + i, expRecord, actRecord);
        }
    }
    tsID.remove();
}
Also used : CommandContext(org.teiid.query.util.CommandContext) TupleSource(org.teiid.common.buffer.TupleSource) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager) BlockedException(org.teiid.common.buffer.BlockedException)

Example 39 with TupleBuffer

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

the class TestJoinNode method testSortMergeWithDistinct.

@Test
public void testSortMergeWithDistinct() throws TeiidComponentException, TeiidProcessingException {
    this.leftTuples = new List[] { Arrays.asList(1, 2), Arrays.asList(1, 3) };
    this.rightTuples = new List[] { Arrays.asList(1, 4), Arrays.asList(1, 5) };
    expected = new List[] { Arrays.asList(1, 2, 1, 4), Arrays.asList(1, 2, 1, 5), Arrays.asList(1, 3, 1, 4), Arrays.asList(1, 3, 1, 5) };
    // $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 = Arrays.asList(es1, es2);
    leftNode = new BlockingFakeRelationalNode(1, leftTuples);
    leftNode.setElements(leftElements);
    // $NON-NLS-1$
    ElementSymbol es3 = new ElementSymbol("e3");
    es3.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es4 = new ElementSymbol("e4");
    es4.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List rightElements = Arrays.asList(es3, es4);
    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.addAll(leftElements);
    joinElements.addAll(rightElements);
    joinType = JoinType.JOIN_INNER;
    joinStrategy = new MergeJoinStrategy(SortOption.SORT_DISTINCT, SortOption.SORT_DISTINCT, false);
    join = new JoinNode(3);
    join.setElements(joinElements);
    join.setJoinType(joinType);
    join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es3));
    join.setJoinStrategy(joinStrategy);
    helpTestJoinDirect(expected, 100, 100000);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ArrayList(java.util.ArrayList) BlockedException(org.teiid.common.buffer.BlockedException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) Test(org.junit.Test)

Example 40 with TupleBuffer

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

the class TestSortNode method testSortLimit.

@Test
public void testSortLimit() throws Exception {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$
    TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es1), "test", TupleSourceType.PROCESSOR);
    tsid.addTuple(Arrays.asList(4));
    tsid.addTuple(Arrays.asList(3));
    tsid.addTuple(Arrays.asList(2));
    tsid.addTuple(Arrays.asList(1));
    tsid.close();
    // $NON-NLS-1$
    SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema());
    su.setBatchSize(2);
    TupleBuffer out = su.sort(2);
    TupleSource ts = out.createIndexedTupleSource();
    assertEquals(Arrays.asList(1), ts.nextTuple());
    assertEquals(Arrays.asList(2), ts.nextTuple());
    assertNull(ts.nextTuple());
    // $NON-NLS-1$
    su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema());
    su.setBatchSize(10);
    out = su.sort(2);
    ts = out.createIndexedTupleSource();
    assertEquals(Arrays.asList(1), ts.nextTuple());
    assertEquals(Arrays.asList(2), ts.nextTuple());
    assertNull(ts.nextTuple());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleSource(org.teiid.common.buffer.TupleSource) TupleBuffer(org.teiid.common.buffer.TupleBuffer) 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