Search in sources :

Example 51 with TupleBatch

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

the class TestLimitNode method testLimitInFirstBatch.

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

Example 52 with TupleBatch

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

the class TestProjectIntoNode method helpTestNextBatch.

private void helpTestNextBatch(int tupleBatchSize, Mode mode) throws Exception {
    ProjectIntoNode node = new ProjectIntoNode(2);
    TupleSource tupleSource = new FakeDataTupleSource(NUM_ROWS);
    RelationalNode child = new FakeRelationalNode(1, tupleSource, tupleBatchSize);
    node.addChild(child);
    // $NON-NLS-1$
    node.setIntoGroup(new GroupSymbol("myGroup"));
    // $NON-NLS-1$
    ElementSymbol elementSymbol_1 = new ElementSymbol("myGroup.myElement1");
    // $NON-NLS-1$
    ElementSymbol elementSymbol_2 = new ElementSymbol("myGroup.myElement2");
    elementSymbol_1.setType(Integer.class);
    elementSymbol_2.setType(String.class);
    List<ElementSymbol> elements = Arrays.asList(elementSymbol_1, elementSymbol_2);
    node.setIntoElements(elements);
    child.setElements(elements);
    node.setMode(mode);
    // $NON-NLS-1$
    node.setModelName("myModel");
    CommandContext context = new CommandContext();
    BufferManager bm = BufferManagerFactory.getTestBufferManager(tupleBatchSize, tupleBatchSize);
    ProcessorDataManager dataManager = new FakePDM(tupleBatchSize);
    child.initialize(context, bm, dataManager);
    node.initialize(context, bm, dataManager);
    node.open();
    TupleBatch batch = null;
    // Do the remaining batches
    while (true) {
        try {
            batch = node.nextBatch();
            break;
        } catch (BlockedException e) {
        // Normal
        }
    }
    assertNotNull(batch);
    List[] tuples = batch.getAllTuples();
    assertEquals(1, tuples.length);
    Object[] columns = tuples[0].toArray();
    assertNotNull(columns);
    assertEquals(1, columns.length);
    // Should have inserted all rows
    assertEquals(new Integer(NUM_ROWS), columns[0]);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) CommandContext(org.teiid.query.util.CommandContext) ProcessorDataManager(org.teiid.query.processor.ProcessorDataManager) BufferManager(org.teiid.common.buffer.BufferManager) BlockedException(org.teiid.common.buffer.BlockedException) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) FakeTupleSource(org.teiid.query.processor.FakeTupleSource) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) List(java.util.List) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 53 with TupleBatch

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

the class TestProjectNode method helpTestProject.

public void helpTestProject(List elements, List[] data, List childElements, List[] expected, ProcessorDataManager dataMgr) throws TeiidComponentException, TeiidProcessingException {
    ProjectNode projectNode = helpSetupProject(elements, data, childElements, dataMgr);
    projectNode.open();
    int currentRow = 1;
    while (true) {
        try {
            TupleBatch batch = projectNode.nextBatch();
            for (int row = currentRow; row <= batch.getEndRow(); row++) {
                // $NON-NLS-1$
                assertEquals("Rows don't match at " + row, expected[row - 1], batch.getTuple(row));
            }
            if (batch.getTerminationFlag()) {
                break;
            }
            currentRow += batch.getRowCount();
        } catch (BlockedException e) {
        // ignore and try again
        }
    }
}
Also used : BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 54 with TupleBatch

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

the class TestProjectNode method helpTestProjectFails.

public void helpTestProjectFails(List elements, List[] data, List childElements, String expectedError) throws TeiidComponentException, TeiidProcessingException {
    ProjectNode projectNode = helpSetupProject(elements, data, childElements, null);
    try {
        projectNode.open();
        while (true) {
            TupleBatch batch = projectNode.nextBatch();
            if (batch.getTerminationFlag()) {
                break;
            }
        }
        // $NON-NLS-1$
        fail("Expected error but test succeeded");
    } catch (ExpressionEvaluationException e) {
        // note that this should not be a component exception, which would indicate that something abnormal happened
        // $NON-NLS-1$
        assertEquals("Got unexpected exception", expectedError.toUpperCase(), e.getMessage().toUpperCase());
    }
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 55 with TupleBatch

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

the class TestRelationalNodeStatistics method testDescriptionProperties.

@Test
public void testDescriptionProperties() throws Exception {
    List[] data = createData(1000);
    FakeRelationalNode fakeNode = createFakeNode(data);
    // read from fake node
    while (true) {
        TupleBatch batch = fakeNode.nextBatch();
        if (batch.getTerminationFlag()) {
            break;
        }
    }
    // $NON-NLS-1$
    assertEquals("FakeRelationalNode", fakeNode.getDescriptionProperties().getName());
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) 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