use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestBatchIterator method testReadAheadMark.
@Test
public void testReadAheadMark() throws Exception {
BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) }, 2));
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER)), "test", TupleSourceType.PROCESSOR);
// $NON-NLS-1$
bi.setBuffer(tb, true);
bi.nextTuple();
assertEquals(1, bi.available());
assertEquals(0, bi.getBuffer().getRowCount());
bi.readAhead(100);
assertEquals(4, bi.getBuffer().getRowCount());
// shouldn't keep reading
bi.readAhead(2);
assertEquals(4, bi.getBuffer().getRowCount());
bi.readAhead(5);
assertEquals(6, bi.getBuffer().getRowCount());
// does nothing
bi.readAhead(8);
for (int i = 0; i < 6; i++) {
assertNotNull(bi.nextTuple());
}
assertNull(bi.nextTuple());
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestBatchIterator method testReadAhead.
@Test
public void testReadAhead() throws Exception {
BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) }, 2));
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER)), "test", TupleSourceType.PROCESSOR);
// $NON-NLS-1$
bi.setBuffer(tb, false);
bi.nextTuple();
assertEquals(1, bi.available());
assertEquals(2, bi.getBuffer().getRowCount());
bi.readAhead(100);
assertEquals(4, bi.getBuffer().getRowCount());
// shouldn't keep reading
bi.readAhead(3);
assertEquals(4, bi.getBuffer().getRowCount());
bi.readAhead(5);
assertEquals(6, bi.getBuffer().getRowCount());
// does nothing
bi.readAhead(8);
for (int i = 0; i < 5; i++) {
assertNotNull(bi.nextTuple());
}
assertNull(bi.nextTuple());
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestQueryProcessor method helpTestProcessor.
public void helpTestProcessor(FakeProcessorPlan plan, List[] expectedResults) throws TeiidException {
BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
FakeDataManager dataManager = new FakeDataManager();
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "group", null, null, 1);
QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
BatchCollector collector = processor.createBatchCollector();
TupleBuffer tsID = null;
while (true) {
try {
tsID = collector.collectTuples();
break;
} catch (BlockedException e) {
}
}
// Compare # of rows in actual and expected
// $NON-NLS-1$
assertEquals("Did not get expected # of rows", expectedResults.length, tsID.getRowCount());
// Compare actual with expected results
TupleSource actual = tsID.createIndexedTupleSource();
if (expectedResults.length > 0) {
for (int i = 0; i < expectedResults.length; i++) {
List actRecord = actual.nextTuple();
List expRecord = expectedResults[i];
// $NON-NLS-1$
assertEquals("Did not match row at row index " + i, expRecord, actRecord);
}
}
tsID.remove();
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestJoinNode method testSortMergeWithDistinct.
@Test
public void testSortMergeWithDistinct() throws TeiidComponentException, TeiidProcessingException {
this.leftTuples = new List[] { Arrays.asList(1, 2), Arrays.asList(1, 3) };
this.rightTuples = new List[] { Arrays.asList(1, 4), Arrays.asList(1, 5) };
expected = new List[] { Arrays.asList(1, 2, 1, 4), Arrays.asList(1, 2, 1, 5), Arrays.asList(1, 3, 1, 4), Arrays.asList(1, 3, 1, 5) };
// $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);
List leftElements = Arrays.asList(es1, es2);
leftNode = new BlockingFakeRelationalNode(1, leftTuples);
leftNode.setElements(leftElements);
// $NON-NLS-1$
ElementSymbol es3 = new ElementSymbol("e3");
es3.setType(DataTypeManager.DefaultDataClasses.INTEGER);
// $NON-NLS-1$
ElementSymbol es4 = new ElementSymbol("e4");
es4.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List rightElements = Arrays.asList(es3, es4);
rightNode = new BlockingFakeRelationalNode(2, rightTuples) {
@Override
public boolean hasBuffer() {
return false;
}
@Override
public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
fail();
throw new AssertionError();
}
};
rightNode.setElements(rightElements);
List joinElements = new ArrayList();
joinElements.addAll(leftElements);
joinElements.addAll(rightElements);
joinType = JoinType.JOIN_INNER;
joinStrategy = new MergeJoinStrategy(SortOption.SORT_DISTINCT, SortOption.SORT_DISTINCT, false);
join = new JoinNode(3);
join.setElements(joinElements);
join.setJoinType(joinType);
join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es3));
join.setJoinStrategy(joinStrategy);
helpTestJoinDirect(expected, 100, 100000);
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestSortNode method testSortLimit.
@Test
public void testSortLimit() 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(4));
tsid.addTuple(Arrays.asList(3));
tsid.addTuple(Arrays.asList(2));
tsid.addTuple(Arrays.asList(1));
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(2);
TupleBuffer out = su.sort(2);
TupleSource ts = out.createIndexedTupleSource();
assertEquals(Arrays.asList(1), ts.nextTuple());
assertEquals(Arrays.asList(2), ts.nextTuple());
assertNull(ts.nextTuple());
// $NON-NLS-1$
su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema());
su.setBatchSize(10);
out = su.sort(2);
ts = out.createIndexedTupleSource();
assertEquals(Arrays.asList(1), ts.nextTuple());
assertEquals(Arrays.asList(2), ts.nextTuple());
assertNull(ts.nextTuple());
}
Aggregations