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());
}
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());
}
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();
}
Aggregations