Search in sources :

Example 31 with TupleSource

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

Aggregations

TupleSource (org.teiid.common.buffer.TupleSource)31 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)11 Test (org.junit.Test)10 TupleBuffer (org.teiid.common.buffer.TupleBuffer)10 CommandContext (org.teiid.query.util.CommandContext)10 List (java.util.List)9 BlockedException (org.teiid.common.buffer.BlockedException)9 TeiidProcessingException (org.teiid.core.TeiidProcessingException)9 Command (org.teiid.query.sql.lang.Command)9 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)9 ArrayList (java.util.ArrayList)6 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)6 RegisterRequestParameter (org.teiid.query.processor.RegisterRequestParameter)6 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)6 BufferManager (org.teiid.common.buffer.BufferManager)5 TeiidComponentException (org.teiid.core.TeiidComponentException)5 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)4 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)4 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)3