Search in sources :

Example 41 with TupleBuffer

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

the class TestSortNode method testStableSort.

@Test
public void testStableSort() throws Exception {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$
    TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es1), "test", TupleSourceType.PROCESSOR);
    tsid.addTuple(Arrays.asList(1, 1));
    tsid.addTuple(Arrays.asList(1, 2));
    tsid.addTuple(Arrays.asList(1, 3));
    tsid.close();
    // $NON-NLS-1$
    SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema());
    su.setBatchSize(1);
    su.setStableSort(true);
    TupleBuffer out = su.sort();
    TupleSource ts = out.createIndexedTupleSource();
    assertEquals(Arrays.asList(1, 1), ts.nextTuple());
    assertEquals(Arrays.asList(1, 2), ts.nextTuple());
    assertEquals(Arrays.asList(1, 3), ts.nextTuple());
    assertNull(ts.nextTuple());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleSource(org.teiid.common.buffer.TupleSource) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 42 with TupleBuffer

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

the class TestSortNode method testDistinct.

@Test
public void testDistinct() throws Exception {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es2 = new ElementSymbol("e2");
    es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$
    TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es2), "test", TupleSourceType.PROCESSOR);
    tsid.addTuple(Arrays.asList(1, 1));
    tsid.addTuple(Arrays.asList(1, 2));
    tsid.close();
    // $NON-NLS-1$
    SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.DUP_REMOVE_SORT, bm, "test", tsid.getSchema());
    su.sort();
    assertFalse(su.isDistinct());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 43 with TupleBuffer

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

TupleBuffer (org.teiid.common.buffer.TupleBuffer)43 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)19 BufferManager (org.teiid.common.buffer.BufferManager)16 List (java.util.List)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)11 BlockedException (org.teiid.common.buffer.BlockedException)10 TupleSource (org.teiid.common.buffer.TupleSource)10 CommandContext (org.teiid.query.util.CommandContext)7 TeiidProcessingException (org.teiid.core.TeiidProcessingException)6 FakeRelationalNode (org.teiid.query.processor.relational.FakeRelationalNode)6 TeiidComponentException (org.teiid.core.TeiidComponentException)5 TupleBatch (org.teiid.common.buffer.TupleBatch)4 Map (java.util.Map)3 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)3 Expression (org.teiid.query.sql.symbol.Expression)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 IndexedTupleSource (org.teiid.common.buffer.IndexedTupleSource)2