Search in sources :

Example 16 with TupleBatch

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

the class TestBatchedUpdateNode method helpTestNextBatch.

private FakePDM helpTestNextBatch(String[] commands, int[] expectedResults) throws Exception {
    int numExecutedCommands = 0;
    for (int i = 0; i < expectedResults.length; i++) {
        numExecutedCommands += expectedResults[i];
    }
    FakePDM fakePDM = new FakePDM(numExecutedCommands);
    BatchedUpdateNode node = helpOpen(commands, fakePDM);
    TupleBatch batch = null;
    try {
        batch = node.nextBatch();
    } catch (BlockedException e) {
        batch = node.nextBatch();
    }
    assertNotNull(batch);
    assertTrue(batch.getTerminationFlag());
    assertEquals(expectedResults.length, batch.getRowCount());
    for (int i = 0; i < expectedResults.length; i++) {
        List tuple = batch.getTuple(i + 1);
        assertNotNull(tuple);
        Object result = tuple.get(0);
        assertNotNull(result);
        assertEquals(new Integer(expectedResults[i]), result);
    }
    return fakePDM;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 17 with TupleBatch

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

the class TestJoinNode method process.

private void process(List[] expectedResults) throws TeiidComponentException, TeiidProcessingException {
    join.open();
    int currentRow = 1;
    while (true) {
        try {
            TupleBatch batch = join.nextBatch();
            for (; currentRow <= batch.getEndRow(); currentRow++) {
                List tuple = batch.getTuple(currentRow);
                // $NON-NLS-1$
                assertEquals("Rows don't match at " + currentRow, expectedResults[currentRow - 1], tuple);
            }
            if (batch.getTerminationFlag()) {
                break;
            }
        } catch (BlockedException e) {
        // ignore and retry
        }
    }
    assertEquals(expectedResults.length, currentRow - 1);
    join.close();
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 18 with TupleBatch

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

the class TestJoinNode method testMergeJoinPrefetchAlreadySorted.

@Test
public void testMergeJoinPrefetchAlreadySorted() throws Exception {
    this.joinType = JoinType.JOIN_INNER;
    int rows = 50;
    List[] data = new List[rows];
    for (int i = 0; i < rows; i++) {
        data[i] = new ArrayList();
        Integer value = new Integer((i * 17) % 47);
        data[i].add(value);
    }
    this.leftTuples = data;
    this.rightTuples = new List[] { Arrays.asList(1), Arrays.asList(2), Arrays.asList(4), Arrays.asList(6), Arrays.asList(7), Arrays.asList(8) };
    expected = new List[] { Arrays.asList(new Object[] { 1, 1 }), Arrays.asList(new Object[] { 2, 2 }), Arrays.asList(new Object[] { 4, 4 }), Arrays.asList(new Object[] { 6, 6 }), Arrays.asList(new Object[] { 7, 7 }), Arrays.asList(new Object[] { 8, 8 }) };
    helpCreateJoin();
    this.joinStrategy = new MergeJoinStrategy(SortOption.SORT, SortOption.ALREADY_SORTED, false);
    BlockingFakeRelationalNode newNode = new BlockingFakeRelationalNode(2, rightTuples) {

        @Override
        public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
            TupleBatch tb = super.nextBatchDirect();
            if (tb.getTerminationFlag()) {
                assertFalse(leftNode.isClosed());
            }
            return tb;
        }
    };
    newNode.setElements(rightNode.getElements());
    rightNode = newNode;
    this.join.setJoinStrategy(joinStrategy);
    helpTestJoinDirect(expected, 5, 1);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Example 19 with TupleBatch

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

the class TestLimitNode method testLimitMultipleOfBatchSize.

@Test
public void testLimitMultipleOfBatchSize() throws Exception {
    LimitNode node = getLimitNode(100, new FakeRelationalNode(2, getRows(150), 50));
    TupleBatch batch = node.nextBatch();
    assertNotNull(batch);
    assertEquals(50, batch.getRowCount());
    assertEquals(1, batch.getBeginRow());
    assertEquals(50, batch.getEndRow());
    assertFalse(batch.getTerminationFlag());
    batch = node.nextBatch();
    assertEquals(50, batch.getRowCount());
    assertEquals(51, batch.getBeginRow());
    assertEquals(100, batch.getEndRow());
    assertTrue(batch.getTerminationFlag());
}
Also used : TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Example 20 with TupleBatch

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

the class TestLimitNode method testLimitAtBatchSize.

@Test
public void testLimitAtBatchSize() throws Exception {
    LimitNode node = getLimitNode(50, new FakeRelationalNode(2, getRows(100), 50));
    TupleBatch batch = node.nextBatch();
    assertNotNull(batch);
    assertEquals(50, batch.getRowCount());
    assertEquals(1, batch.getBeginRow());
    assertEquals(50, batch.getEndRow());
    assertTrue(batch.getTerminationFlag());
}
Also used : TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Aggregations

TupleBatch (org.teiid.common.buffer.TupleBatch)61 Test (org.junit.Test)26 List (java.util.List)23 ArrayList (java.util.ArrayList)22 BlockedException (org.teiid.common.buffer.BlockedException)17 CommandContext (org.teiid.query.util.CommandContext)10 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)9 TeiidProcessingException (org.teiid.core.TeiidProcessingException)8 TeiidComponentException (org.teiid.core.TeiidComponentException)6 BufferManager (org.teiid.common.buffer.BufferManager)4 TupleBuffer (org.teiid.common.buffer.TupleBuffer)4 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)3 TransactionContext (org.teiid.dqp.service.TransactionContext)3 TransactionService (org.teiid.dqp.service.TransactionService)3 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)2 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)2 TeiidException (org.teiid.core.TeiidException)2 QueryProcessor (org.teiid.query.processor.QueryProcessor)2 FakeRelationalNode (org.teiid.query.processor.relational.FakeRelationalNode)2 CacheHint (org.teiid.query.sql.lang.CacheHint)2