use of org.teiid.query.processor.FakeTupleSource in project teiid by teiid.
the class TestGroupingNode method testDefect5769.
@Test
public void testDefect5769() throws Exception {
BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
// $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);
// $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 BigDecimal("0.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new BigDecimal("1.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new BigDecimal("2.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new BigDecimal("3.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new BigDecimal("4.0") }) };
List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
Arrays.asList(new Object[] { new BigDecimal("10.0"), new BigDecimal("2.0") }) };
List symbols = new ArrayList();
symbols.add(bigDecimal);
FakeTupleSource dataSource = new FakeTupleSource(symbols, data);
helpProcess(mgr, node, context, expected, dataSource, null);
}
use of org.teiid.query.processor.FakeTupleSource in project teiid by teiid.
the class TestGroupingNode method createTupleSource1.
public static FakeTupleSource createTupleSource1() {
List<ElementSymbol> symbols = new ArrayList<ElementSymbol>();
// $NON-NLS-1$
symbols.add(new ElementSymbol("col1"));
symbols.get(0).setType(DataTypeManager.DefaultDataClasses.INTEGER);
// $NON-NLS-1$
symbols.add(new ElementSymbol("col2"));
symbols.get(1).setType(DataTypeManager.DefaultDataClasses.INTEGER);
List[] tuples = new List[] { Arrays.asList(new Object[] { new Integer(5), new Integer(3) }), Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), Arrays.asList(new Object[] { new Integer(4), null }), Arrays.asList(new Object[] { null, new Integer(3) }), Arrays.asList(new Object[] { new Integer(0), new Integer(4) }), Arrays.asList(new Object[] { new Integer(1), new Integer(2) }), Arrays.asList(new Object[] { new Integer(4), new Integer(2) }), Arrays.asList(new Object[] { new Integer(6), new Integer(4) }), Arrays.asList(new Object[] { new Integer(6), new Integer(3) }), Arrays.asList(new Object[] { new Integer(3), new Integer(0) }), Arrays.asList(new Object[] { new Integer(4), new Integer(3) }), Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), Arrays.asList(new Object[] { new Integer(2), new Integer(2) }), Arrays.asList(new Object[] { null, null }) };
return new FakeTupleSource(symbols, tuples);
}
use of org.teiid.query.processor.FakeTupleSource in project teiid by teiid.
the class TestGroupingNode method testBlocking.
@Test
public void testBlocking() throws Exception {
BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
// $NON-NLS-1$
ElementSymbol bigDecimal = new ElementSymbol("value");
bigDecimal.setType(DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
// Set up
GroupingNode node = new GroupingNode(1) {
boolean block = true;
@Override
protected void closeGroup(int colDiff, boolean reset, CommandContext context) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException {
if (block) {
block = false;
throw BlockedException.INSTANCE;
}
block = true;
super.closeGroup(colDiff, reset, context);
}
};
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);
// $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 BigDecimal("0.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new BigDecimal("1.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new BigDecimal("2.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new BigDecimal("3.0") }), // $NON-NLS-1$
Arrays.asList(new Object[] { new BigDecimal("4.0") }) };
List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
Arrays.asList(new Object[] { new BigDecimal("10.0"), new BigDecimal("2.0") }) };
List symbols = new ArrayList();
symbols.add(bigDecimal);
FakeTupleSource dataSource = new FakeTupleSource(symbols, data) {
boolean end;
@Override
public List nextTuple() throws TeiidComponentException {
List result = super.nextTuple();
if (end) {
fail();
}
end = result == null;
return result;
}
};
helpProcess(mgr, node, context, expected, dataSource, null);
}
use of org.teiid.query.processor.FakeTupleSource in project teiid by teiid.
the class TestGroupingNode method helpProcess.
private void helpProcess(BufferManager mgr, GroupingNode node, CommandContext context, List[] expected, ProcessorDataManager dataMgr) throws TeiidComponentException, BlockedException, TeiidProcessingException {
FakeTupleSource dataSource = createTupleSource1();
helpProcess(mgr, node, context, expected, dataSource, dataMgr);
}
use of org.teiid.query.processor.FakeTupleSource 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);
}
Aggregations