Search in sources :

Example 41 with TupleBatch

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

the class TestQueryProcessor method testBlockNoResults.

@Test
public void testBlockNoResults() throws Exception {
    List elements = new ArrayList();
    // $NON-NLS-1$
    elements.add(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER));
    List batches = new ArrayList();
    batches.add(BlockedException.INSTANCE);
    TupleBatch batch = new TupleBatch(1, new List[0]);
    batch.setTerminationFlag(true);
    batches.add(batch);
    FakeProcessorPlan plan = new FakeProcessorPlan(elements, batches);
    helpTestProcessor(plan, new List[0]);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Example 42 with TupleBatch

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

the class FakeRelationalNode method nextBatchDirect.

/**
 * @throws TeiidProcessingException
 * @see com.metamatrix.query.processor.relational.x.RelationalNode#nextBatch()
 */
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
    if (data != null) {
        if (currentRow < data.length) {
            int endRow = Math.min(data.length, currentRow + getBatchSize());
            List batchRows = new ArrayList();
            for (int i = currentRow; i < endRow; i++) {
                batchRows.add(data[i]);
            }
            TupleBatch batch = new TupleBatch(currentRow + 1, batchRows);
            currentRow += batch.getRowCount();
            if (currentRow >= data.length) {
                batch.setTerminationFlag(true);
            }
            return batch;
        }
        TupleBatch batch = new TupleBatch(currentRow + 1, Collections.EMPTY_LIST);
        batch.setTerminationFlag(true);
        return batch;
    }
    boolean last = false;
    List rows = new ArrayList(batchSize);
    for (int i = 0; i < batchSize; i++) {
        List tuple = source.nextTuple();
        if (tuple == null) {
            last = true;
            break;
        }
        rows.add(tuple);
    }
    TupleBatch batch = new TupleBatch(currentRow + 1, rows);
    if (last) {
        batch.setTerminationFlag(true);
    } else {
        currentRow += rows.size();
    }
    return batch;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 43 with TupleBatch

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

the class TestGroupingNode method helpProcess.

private void helpProcess(BufferManager mgr, GroupingNode node, CommandContext context, List[] expected, FakeTupleSource dataSource, ProcessorDataManager dataMgr) throws TeiidComponentException, BlockedException, TeiidProcessingException {
    RelationalNode dataNode = new FakeRelationalNode(0, dataSource, mgr.getProcessorBatchSize());
    dataNode.setElements(dataSource.getSchema());
    node.addChild(dataNode);
    node.initialize(context, mgr, dataMgr);
    node.open();
    int currentRow = 1;
    while (true) {
        try {
            TupleBatch batch = node.nextBatch();
            for (int row = currentRow; row <= batch.getEndRow(); row++) {
                List tuple = batch.getTuple(row);
                // $NON-NLS-1$
                assertEquals("Rows don't match at " + row, expected[row - 1], tuple);
            }
            currentRow += batch.getRowCount();
            if (batch.getTerminationFlag()) {
                break;
            }
        } catch (BlockedException e) {
        // ignore
        }
    }
    assertEquals(expected.length, currentRow - 1);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 44 with TupleBatch

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

the class TestLimitNode method testOffsetInFirstBatch.

@Test
public void testOffsetInFirstBatch() throws Exception {
    LimitNode node = getOffsetNode(49, new FakeRelationalNode(2, getRows(100), 50));
    // batch 1
    TupleBatch batch = node.nextBatch();
    assertNotNull(batch);
    assertEquals(1, batch.getRowCount());
    assertEquals(1, batch.getBeginRow());
    assertEquals(1, batch.getEndRow());
    assertEquals(Arrays.asList(new Object[] { new Integer(50) }), batch.getTuple(1));
    assertFalse(batch.getTerminationFlag());
    // batch2
    batch = node.nextBatch();
    assertNotNull(batch);
    assertEquals(50, batch.getRowCount());
    assertEquals(2, batch.getBeginRow());
    assertEquals(51, batch.getEndRow());
    assertEquals(Arrays.asList(new Object[] { new Integer(51) }), batch.getTuple(2));
    assertTrue(batch.getTerminationFlag());
}
Also used : TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Example 45 with TupleBatch

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

the class TestLimitNode method testOffsetNoRows.

@Test
public void testOffsetNoRows() throws Exception {
    LimitNode node = getOffsetNode(100, new FakeRelationalNode(2, getRows(0), 50));
    TupleBatch batch = node.nextBatch();
    assertNotNull(batch);
    assertEquals(0, batch.getRowCount());
    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