use of org.teiid.query.sql.symbol.AggregateSymbol in project teiid by teiid.
the class TestGroupingNode method test1.
// ################################## ACTUAL TESTS ################################
@Test
public void test1() throws Exception {
BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
// Set up
GroupingNode node = new GroupingNode(1);
List outputElements = new ArrayList();
// $NON-NLS-1$
ElementSymbol col1 = new ElementSymbol("col1");
col1.setType(Integer.class);
// $NON-NLS-1$
ElementSymbol col2 = new ElementSymbol("col2");
col2.setType(Integer.class);
outputElements.add(col1);
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("COUNT", false, null));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("COUNT", false, col2));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("COUNT", true, col2));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("SUM", false, col2));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("SUM", true, col2));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("AVG", false, col2));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("AVG", true, col2));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("MIN", false, col2));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("MIN", true, col2));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("MAX", false, col2));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("MAX", true, col2));
node.setElements(outputElements);
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[] expected = new List[] { Arrays.asList(new Object[] { null, new Integer(2), new Integer(1), new Integer(1), new Long(3), new Long(3), new BigDecimal(3.0), new BigDecimal(3.0), new Integer(3), new Integer(3), new Integer(3), new Integer(3) }), Arrays.asList(new Object[] { new Integer(0), new Integer(1), new Integer(1), new Integer(1), new Long(4), new Long(4), new BigDecimal(4.0), new BigDecimal(4.0), new Integer(4), new Integer(4), new Integer(4), new Integer(4) }), Arrays.asList(new Object[] { new Integer(1), new Integer(1), new Integer(1), new Integer(1), new Long(2), new Long(2), new BigDecimal(2.0), new BigDecimal(2.0), new Integer(2), new Integer(2), new Integer(2), new Integer(2) }), Arrays.asList(new Object[] { new Integer(2), new Integer(4), new Integer(4), new Integer(2), new Long(5), new Long(3), new BigDecimal(1.25), new BigDecimal(1.5), new Integer(1), new Integer(1), new Integer(2), new Integer(2) }), Arrays.asList(new Object[] { new Integer(3), new Integer(1), new Integer(1), new Integer(1), new Long(0), new Long(0), new BigDecimal(0.0), new BigDecimal(0.0), new Integer(0), new Integer(0), new Integer(0), new Integer(0) }), Arrays.asList(new Object[] { new Integer(4), new Integer(3), new Integer(2), new Integer(2), new Long(5), new Long(5), new BigDecimal(2.5), new BigDecimal(2.5), new Integer(2), new Integer(2), new Integer(3), new Integer(3) }), Arrays.asList(new Object[] { new Integer(5), new Integer(1), new Integer(1), new Integer(1), new Long(3), new Long(3), new BigDecimal(3.0), new BigDecimal(3.0), new Integer(3), new Integer(3), new Integer(3), new Integer(3) }), Arrays.asList(new Object[] { new Integer(6), new Integer(2), new Integer(2), new Integer(2), new Long(7), new Long(7), new BigDecimal(3.5), new BigDecimal(3.5), new Integer(3), new Integer(3), new Integer(4), new Integer(4) }) };
helpProcess(mgr, node, context, expected, null);
// ensure that the distinct input type is correct
AggregateFunction[][] functions = node.getFunctions();
AggregateFunction countDist = functions[5][0];
SortingFilter dup = (SortingFilter) countDist;
assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, dup.getElements().get(0).getType());
}
use of org.teiid.query.sql.symbol.AggregateSymbol 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.sql.symbol.AggregateSymbol in project teiid by teiid.
the class TestGroupingNode method testDescriptionProperties.
@Test
public void testDescriptionProperties() {
GroupingNode node = getExampleGroupingNode();
SymbolMap outputMapping = new SymbolMap();
outputMapping.addMapping(new ElementSymbol("agg0"), new AggregateSymbol("count", false, null));
node.setOutputMapping(outputMapping);
PlanNode pn = node.getDescriptionProperties();
assertTrue(pn.toString().contains("agg0=count(*)"));
}
use of org.teiid.query.sql.symbol.AggregateSymbol in project teiid by teiid.
the class TestGroupingNode method getExampleGroupingNode.
private GroupingNode getExampleGroupingNode() {
GroupingNode node = new GroupingNode(1);
List outputElements = new ArrayList();
// $NON-NLS-1$
ElementSymbol col1 = new ElementSymbol("col1");
col1.setType(Integer.class);
// $NON-NLS-1$
ElementSymbol col2 = new ElementSymbol("col2");
col2.setType(Integer.class);
outputElements.add(col1);
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("COUNT", true, col2));
node.setElements(outputElements);
List groupingElements = new ArrayList();
groupingElements.add(col1);
node.setOrderBy(new OrderBy(groupingElements).getOrderByItems());
return node;
}
use of org.teiid.query.sql.symbol.AggregateSymbol in project teiid by teiid.
the class TestCapabilitiesUtil method testSupportsAggregate16.
@Test
public void testSupportsAggregate16() throws Exception {
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_DISTINCT, true);
// $NON-NLS-1$ //$NON-NLS-2$
AggregateSymbol aggregate = new AggregateSymbol(NonReserved.MAX, true, new ElementSymbol("x"));
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
Aggregations