use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestJoinNode method helpCreateJoin.
protected void helpCreateJoin() {
// $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 = new ArrayList();
leftElements.add(es1);
leftNode = new BlockingFakeRelationalNode(1, leftTuples);
leftNode.setElements(leftElements);
List rightElements = new ArrayList();
rightElements.add(es2);
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.add(es1);
joinElements.add(es2);
join = new JoinNode(3);
joinStrategy = new NestedLoopJoinStrategy();
join.setJoinStrategy(joinStrategy);
join.setElements(joinElements);
join.setJoinType(joinType);
switch(criteriaType) {
case NO_CRITERIA:
break;
case EQUAL_CRITERIA:
join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es2));
joinStrategy = new MergeJoinStrategy(SortOption.SORT, SortOption.SORT, false);
join.setJoinStrategy(joinStrategy);
break;
case FUNCTION_CRITERIA:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), es1 });
// $NON-NLS-1$
FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class });
func.setFunctionDescriptor(desc);
func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
CompareCriteria joinCriteria = new CompareCriteria(es2, CompareCriteria.EQ, func);
join.setJoinCriteria(joinCriteria);
break;
}
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestSortNode method testOnePass.
@Test
public void testOnePass() 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.SORT, bm, "test", tsid.getSchema());
List<TupleBuffer> buffers = su.onePassSort(true);
assertEquals(1, buffers.size());
assertTrue(!buffers.get(0).isForwardOnly());
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestBatchIterator method testDisableSave.
@Test
public void testDisableSave() 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.setPosition(2);
assertTrue(bi.hasNext());
tb.setForwardOnly(true);
bi.setPosition(1);
bi.disableSave();
for (int i = 0; i < 6; i++) {
assertNotNull(bi.nextTuple());
}
assertNull(bi.nextTuple());
assertEquals(0, tb.getManagedRowCount());
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestBatchIterator method testReset1.
@Test
public void testReset1() throws Exception {
BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(2), Arrays.asList(3) }, 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();
bi.mark();
bi.nextTuple();
bi.reset();
assertEquals(2, bi.getCurrentIndex());
assertEquals(2, bi.nextTuple().get(0));
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestBatchIterator method testReset2.
@Test
public void testReset2() throws Exception {
BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(2) }, 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.hasNext();
bi.mark();
bi.nextTuple();
bi.nextTuple();
assertNull(bi.nextTuple());
bi.reset();
bi.hasNext();
assertEquals(1, bi.getCurrentIndex());
assertEquals(1, bi.nextTuple().get(0));
}
Aggregations