Search in sources :

Example 41 with BlockedException

use of org.teiid.common.buffer.BlockedException 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 42 with BlockedException

use of org.teiid.common.buffer.BlockedException 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 43 with BlockedException

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

the class TestSelectNode method helpTestSelect.

private void helpTestSelect(List elements, Criteria criteria, List childElements, ProcessorDataManager dataMgr, List[] expected, RelationalNode child, SelectNode selectNode) throws TeiidComponentException, TeiidProcessingException {
    BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    child.setElements(childElements);
    child.initialize(context, mgr, dataMgr);
    selectNode.setCriteria(criteria);
    selectNode.setElements(elements);
    selectNode.addChild(child);
    selectNode.initialize(context, mgr, dataMgr);
    selectNode.open();
    BatchIterator iterator = new BatchIterator(selectNode);
    for (int i = 0; i < expected.length; i++) {
        while (true) {
            try {
                // $NON-NLS-1$
                assertEquals("Rows don't match at " + i, expected[i], iterator.nextTuple());
                break;
            } catch (BlockedException e) {
                continue;
            }
        }
    }
    assertFalse(iterator.hasNext());
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BatchIterator(org.teiid.query.processor.BatchIterator) BufferManager(org.teiid.common.buffer.BufferManager) BlockedException(org.teiid.common.buffer.BlockedException)

Example 44 with BlockedException

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

the class TestSortNode method helpTestSort.

private void helpTestSort(List elements, List[] data, List sortElements, List sortTypes, List[] expected, Mode mode) throws TeiidComponentException, TeiidProcessingException {
    BufferManagerImpl mgr = BufferManagerFactory.getTestBufferManager(10000, BATCH_SIZE);
    long reserve = mgr.getReserveBatchBytes();
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    BlockingFakeRelationalNode dataNode = new BlockingFakeRelationalNode(2, data);
    dataNode.setReturnPeriod(3);
    dataNode.setElements(elements);
    dataNode.initialize(context, mgr, null);
    SortNode sortNode = new SortNode(1);
    sortNode.setSortElements(new OrderBy(sortElements, sortTypes).getOrderByItems());
    sortNode.setMode(mode);
    sortNode.setElements(elements);
    sortNode.addChild(dataNode);
    sortNode.initialize(context, mgr, null);
    sortNode.open();
    assertTrue(sortNode.hasBuffer());
    int currentRow = 1;
    while (true) {
        try {
            TupleBatch batch = sortNode.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));
            }
            currentRow += batch.getRowCount();
            if (batch.getTerminationFlag()) {
                break;
            }
        } catch (BlockedException e) {
        }
    }
    assertEquals(expected.length, currentRow - 1);
    assertEquals(reserve, mgr.getReserveBatchBytes());
}
Also used : OrderBy(org.teiid.query.sql.lang.OrderBy) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) CommandContext(org.teiid.query.util.CommandContext) DupRemoveSortNode(org.teiid.query.optimizer.TestOptimizer.DupRemoveSortNode) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 45 with BlockedException

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

the class TestUnionAllNode method helpTestUnion.

public void helpTestUnion(RelationalNode[] children, RelationalNode union, List[] expected) throws TeiidComponentException, TeiidProcessingException {
    BufferManager mgr = BufferManagerFactory.getTestBufferManager(1, 2);
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    FakeDataManager fdm = new FakeDataManager();
    for (int i = 0; i < children.length; i++) {
        union.addChild(children[i]);
        children[i].initialize(context, mgr, fdm);
    }
    union.initialize(context, mgr, fdm);
    union.open();
    int currentRow = 1;
    while (true) {
        try {
            TupleBatch batch = union.nextBatch();
            for (int row = currentRow; row <= batch.getEndRow(); row++) {
                List tuple = batch.getTuple(row);
                // System.out.println(tuple);
                // $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 and retry
        }
    }
    union.close();
    // $NON-NLS-1$
    assertEquals("Didn't match expected counts", expected.length, currentRow - 1);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) FakeDataManager(org.teiid.query.processor.FakeDataManager) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Aggregations

BlockedException (org.teiid.common.buffer.BlockedException)45 TupleBatch (org.teiid.common.buffer.TupleBatch)16 ArrayList (java.util.ArrayList)15 List (java.util.List)15 TeiidProcessingException (org.teiid.core.TeiidProcessingException)15 TeiidComponentException (org.teiid.core.TeiidComponentException)13 TupleBuffer (org.teiid.common.buffer.TupleBuffer)10 CommandContext (org.teiid.query.util.CommandContext)10 TupleSource (org.teiid.common.buffer.TupleSource)8 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)8 Test (org.junit.Test)6 BufferManager (org.teiid.common.buffer.BufferManager)6 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)5 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)5 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)5 Command (org.teiid.query.sql.lang.Command)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)4 SQLException (java.sql.SQLException)3 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)3