use of org.teiid.common.buffer.BufferManager in project teiid by teiid.
the class TestGroupingNode method helpTestEmptyGroup.
public void helpTestEmptyGroup(boolean groupBy) throws Exception {
BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
// $NON-NLS-1$
ElementSymbol col1 = new ElementSymbol("col1");
col1.setType(Integer.class);
// $NON-NLS-1$
ElementSymbol bigDecimal = new ElementSymbol("value");
bigDecimal.setType(DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
// Set up
GroupingNode node = new GroupingNode(1);
List outputElements = new ArrayList();
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("SUM", false, bigDecimal));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("AVG", false, bigDecimal));
node.setElements(outputElements);
// Set grouping elements to null
if (groupBy) {
List groupingElements = new ArrayList();
// $NON-NLS-1$
groupingElements.add(col1.clone());
node.setOrderBy(new OrderBy(groupingElements).getOrderByItems());
}
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "test", null, null, 1);
List[] data = new List[] {};
List[] expected = new List[] { Arrays.asList(new Object[] { null, null }) };
if (groupBy) {
expected = new List[] {};
}
List symbols = new ArrayList();
symbols.add(col1);
symbols.add(bigDecimal);
FakeTupleSource dataSource = new FakeTupleSource(symbols, data);
helpProcess(mgr, node, context, expected, dataSource, null);
}
use of org.teiid.common.buffer.BufferManager in project teiid by teiid.
the class TestGroupingNode method testdefect9842.
@Test
public void testdefect9842() throws Exception {
BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
// $NON-NLS-1$
ElementSymbol col1 = new ElementSymbol("col1");
col1.setType(Integer.class);
// $NON-NLS-1$
ElementSymbol bigDecimal = new ElementSymbol("value");
bigDecimal.setType(DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
// Set up
GroupingNode node = new GroupingNode(1);
List outputElements = new ArrayList();
outputElements.add(col1);
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("SUM", false, bigDecimal));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("AVG", false, bigDecimal));
node.setElements(outputElements);
// Set grouping elements to null
List groupingElements = new ArrayList();
groupingElements.add(col1);
node.setOrderBy(new OrderBy(groupingElements).getOrderByItems());
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "test", null, null, 1);
List[] data = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { new Integer(1), new BigDecimal("0.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new Integer(1), new BigDecimal("1.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new Integer(2), new BigDecimal("2.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new Integer(2), new BigDecimal("3.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new Integer(2), new BigDecimal("4.0") }) };
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { new Integer(1), new BigDecimal("1.0"), new BigDecimal(.5) }), // $NON-NLS-1$
Arrays.asList(new Object[] { new Integer(2), new BigDecimal("9.0"), new BigDecimal("3.0") }) };
List symbols = new ArrayList();
symbols.add(col1);
symbols.add(bigDecimal);
FakeTupleSource dataSource = new FakeTupleSource(symbols, data);
helpProcess(mgr, node, context, expected, dataSource, null);
}
use of org.teiid.common.buffer.BufferManager in project teiid by teiid.
the class TestProjectIntoNode method helpTestNextBatch.
private void helpTestNextBatch(int tupleBatchSize, Mode mode) throws Exception {
ProjectIntoNode node = new ProjectIntoNode(2);
TupleSource tupleSource = new FakeDataTupleSource(NUM_ROWS);
RelationalNode child = new FakeRelationalNode(1, tupleSource, tupleBatchSize);
node.addChild(child);
// $NON-NLS-1$
node.setIntoGroup(new GroupSymbol("myGroup"));
// $NON-NLS-1$
ElementSymbol elementSymbol_1 = new ElementSymbol("myGroup.myElement1");
// $NON-NLS-1$
ElementSymbol elementSymbol_2 = new ElementSymbol("myGroup.myElement2");
elementSymbol_1.setType(Integer.class);
elementSymbol_2.setType(String.class);
List<ElementSymbol> elements = Arrays.asList(elementSymbol_1, elementSymbol_2);
node.setIntoElements(elements);
child.setElements(elements);
node.setMode(mode);
// $NON-NLS-1$
node.setModelName("myModel");
CommandContext context = new CommandContext();
BufferManager bm = BufferManagerFactory.getTestBufferManager(tupleBatchSize, tupleBatchSize);
ProcessorDataManager dataManager = new FakePDM(tupleBatchSize);
child.initialize(context, bm, dataManager);
node.initialize(context, bm, dataManager);
node.open();
TupleBatch batch = null;
// Do the remaining batches
while (true) {
try {
batch = node.nextBatch();
break;
} catch (BlockedException e) {
// Normal
}
}
assertNotNull(batch);
List[] tuples = batch.getAllTuples();
assertEquals(1, tuples.length);
Object[] columns = tuples[0].toArray();
assertNotNull(columns);
assertEquals(1, columns.length);
// Should have inserted all rows
assertEquals(new Integer(NUM_ROWS), columns[0]);
}
use of org.teiid.common.buffer.BufferManager in project teiid by teiid.
the class TestSelectNode method helpTestSelect.
private void helpTestSelect(List elements, Criteria criteria, List childElements, ProcessorDataManager dataMgr, List[] expected, RelationalNode child, SelectNode selectNode) throws TeiidComponentException, TeiidProcessingException {
BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "test", null, null, 1);
child.setElements(childElements);
child.initialize(context, mgr, dataMgr);
selectNode.setCriteria(criteria);
selectNode.setElements(elements);
selectNode.addChild(child);
selectNode.initialize(context, mgr, dataMgr);
selectNode.open();
BatchIterator iterator = new BatchIterator(selectNode);
for (int i = 0; i < expected.length; i++) {
while (true) {
try {
// $NON-NLS-1$
assertEquals("Rows don't match at " + i, expected[i], iterator.nextTuple());
break;
} catch (BlockedException e) {
continue;
}
}
}
assertFalse(iterator.hasNext());
}
use of org.teiid.common.buffer.BufferManager 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