use of org.teiid.query.sql.symbol.AggregateSymbol in project teiid by teiid.
the class TestCapabilitiesUtil method testSupportsAggregate3.
// Test where capabilities support only COUNT(*)
@Test
public void testSupportsAggregate3() throws Exception {
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, false);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
// $NON-NLS-1$
AggregateSymbol aggregate = new AggregateSymbol(NonReserved.COUNT, false, null);
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
use of org.teiid.query.sql.symbol.AggregateSymbol in project teiid by teiid.
the class TestCapabilitiesUtil method testSupportsAggregate5.
// Test where capabilities support only COUNT
@Test
public void testSupportsAggregate5() throws Exception {
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, false);
// $NON-NLS-1$
AggregateSymbol aggregate = new AggregateSymbol(NonReserved.COUNT, false, null);
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
use of org.teiid.query.sql.symbol.AggregateSymbol in project teiid by teiid.
the class TestGroupingNode method helpTestLookupFunctionInAggregate.
private void helpTestLookupFunctionInAggregate(int batchSize) throws Exception {
BufferManagerImpl mgr = BufferManagerFactory.createBufferManager();
mgr.setProcessorBatchSize(batchSize);
// 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);
// $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"), col2 });
// $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);
outputElements.add(col1);
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("COUNT", false, func));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("SUM", false, func));
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("SUM", true, func));
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);
FakeDataManager dataMgr = new FakeDataManager();
dataMgr.setThrowBlocked(true);
Map valueMap = new HashMap();
valueMap.put(new Integer(0), new Integer(1));
valueMap.put(new Integer(1), new Integer(2));
valueMap.put(new Integer(2), new Integer(3));
valueMap.put(new Integer(3), new Integer(4));
valueMap.put(new Integer(4), new Integer(5));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dataMgr.defineCodeTable("pm1.g1", "e1", "e2", valueMap);
List[] expected = new List[] { Arrays.asList(new Object[] { null, new Integer(1), new Long(4), new Long(4) }), Arrays.asList(new Object[] { new Integer(0), new Integer(1), new Long(5), new Long(5) }), Arrays.asList(new Object[] { new Integer(1), new Integer(1), new Long(3), new Long(3) }), Arrays.asList(new Object[] { new Integer(2), new Integer(4), new Long(9), new Long(5) }), Arrays.asList(new Object[] { new Integer(3), new Integer(1), new Long(1), new Long(1) }), Arrays.asList(new Object[] { new Integer(4), new Integer(2), new Long(7), new Long(7) }), Arrays.asList(new Object[] { new Integer(5), new Integer(1), new Long(4), new Long(4) }), Arrays.asList(new Object[] { new Integer(6), new Integer(2), new Long(9), new Long(9) }) };
helpProcess(mgr, node, context, expected, dataMgr);
}
use of org.teiid.query.sql.symbol.AggregateSymbol 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.query.sql.symbol.AggregateSymbol 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);
}
Aggregations