Search in sources :

Example 56 with TupleBatch

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

the class TestRelationalNodeStatistics method testStatsCollectionBuffer.

@Test
public void testStatsCollectionBuffer() throws TeiidComponentException, TeiidProcessingException {
    List[] data = createData(1000);
    FakeRelationalNode fakeNode = createFakeNode(data);
    fakeNode.setUseBuffer(true);
    // read from fake node
    while (true) {
        TupleBatch batch = fakeNode.nextBatch();
        if (batch.getTerminationFlag()) {
            break;
        }
    }
    int actualNodeBlocks = fakeNode.getNodeStatistics().getNodeBlocks();
    int actualNodeNextBatchCalls = fakeNode.getNodeStatistics().getNodeNextBatchCalls();
    long actualNodeOutputRows = fakeNode.getNodeStatistics().getNodeOutputRows();
    // $NON-NLS-1$
    assertEquals("The NodeOutputRows was Inccorrect. Correct: 1000 Actual: " + actualNodeOutputRows, 1000, actualNodeOutputRows);
    // $NON-NLS-1$
    assertEquals("The NodeNextBatchCalls was Inccorrect. Correct: 10 Actual: " + actualNodeNextBatchCalls, 10, actualNodeNextBatchCalls);
    // $NON-NLS-1$
    assertEquals("The NodeBlocks was Inccorrect. Correct: 0 Actual: " + actualNodeBlocks, 0, actualNodeBlocks);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Example 57 with TupleBatch

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

the class TestSelectNode method testEmptyBatchIndexing.

/**
 * Ensures that a final empty batch is reindexed so that the batch iterator works correctly
 */
@Test
public void testEmptyBatchIndexing() throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List elements = new ArrayList();
    elements.add(es1);
    CompareCriteria crit = new CompareCriteria(new Constant(0), CompareCriteria.EQ, new Constant(new Integer(1)));
    List childElements = new ArrayList();
    childElements.add(es1);
    RelationalNode child = new RelationalNode(0) {

        int i = 0;

        @Override
        public Object clone() {
            return null;
        }

        @Override
        protected TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
            if (i++ == 0) {
                return new TupleBatch(1, new List[] { Arrays.asList(1), Arrays.asList(1) });
            }
            TupleBatch batch = new TupleBatch(3, new List[0]);
            batch.setTerminationFlag(true);
            return batch;
        }
    };
    helpTestSelect(elements, crit, childElements, null, new List[0], child);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Example 58 with TupleBatch

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

use of org.teiid.common.buffer.TupleBatch 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)

Example 60 with TupleBatch

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

the class TestLocalBufferService method testStateTransfer.

@Test
public void testStateTransfer() throws Exception {
    BufferServiceImpl svc = new BufferServiceImpl();
    svc.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/1");
    svc.setUseDisk(true);
    svc.start();
    BufferManager mgr = svc.getBufferManager();
    List<ElementSymbol> schema = new ArrayList<ElementSymbol>(2);
    // $NON-NLS-1$
    ElementSymbol es = new ElementSymbol("x");
    es.setType(DataTypeManager.getDataTypeClass(DefaultDataTypes.STRING));
    schema.add(es);
    // $NON-NLS-1$
    ElementSymbol es2 = new ElementSymbol("y");
    es2.setType(DataTypeManager.getDataTypeClass(DefaultDataTypes.INTEGER));
    schema.add(es2);
    // $NON-NLS-1$
    TupleBuffer buffer = mgr.createTupleBuffer(schema, "cached", TupleSourceType.FINAL);
    buffer.setBatchSize(50);
    buffer.setId("state_id");
    for (int batch = 0; batch < 3; batch++) {
        for (int row = 0; row < 50; row++) {
            int val = (batch * 50) + row;
            buffer.addTuple(Arrays.asList(new Object[] { "String" + val, new Integer(val) }));
        }
    }
    buffer.close();
    mgr.distributeTupleBuffer(buffer.getId(), buffer);
    FileOutputStream fo = new FileOutputStream(UnitTestUtil.getTestScratchPath() + "/teiid/statetest");
    ((BufferManagerImpl) mgr).getState(buffer.getId(), fo);
    fo.close();
    svc.stop();
    // now read back
    BufferServiceImpl svc2 = new BufferServiceImpl();
    svc2.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/2");
    svc2.setUseDisk(true);
    svc2.start();
    BufferManagerImpl mgr2 = svc2.getBufferManager();
    FileInputStream fis = new FileInputStream(UnitTestUtil.getTestScratchPath() + "/teiid/statetest");
    mgr2.setState(buffer.getId(), fis);
    fis.close();
    String id = "state_id";
    buffer = mgr2.getTupleBuffer(id);
    for (int batch = 0; batch < 3; batch++) {
        TupleBatch tb = buffer.getBatch((batch * 50) + 1);
        List[] rows = tb.getAllTuples();
        for (int row = 0; row < 50; row++) {
            int val = (batch * 50) + row;
            assertEquals("String" + val, rows[row].get(0));
            assertEquals(val, rows[row].get(1));
        }
    }
    svc2.stop();
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) ArrayList(java.util.ArrayList) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) FileInputStream(java.io.FileInputStream) BufferServiceImpl(org.teiid.services.BufferServiceImpl) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) 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