Search in sources :

Example 41 with AggregateSymbol

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);
}
Also used : AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Test(org.junit.Test)

Example 42 with AggregateSymbol

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);
}
Also used : AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Test(org.junit.Test)

Example 43 with AggregateSymbol

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderBy(org.teiid.query.sql.lang.OrderBy) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) CommandContext(org.teiid.query.util.CommandContext) FakeDataManager(org.teiid.query.processor.FakeDataManager) HashMap(java.util.HashMap) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Function(org.teiid.query.sql.symbol.Function) AggregateFunction(org.teiid.query.function.aggregate.AggregateFunction) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SymbolMap(org.teiid.query.sql.util.SymbolMap)

Example 44 with AggregateSymbol

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderBy(org.teiid.query.sql.lang.OrderBy) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) CommandContext(org.teiid.query.util.CommandContext) ArrayList(java.util.ArrayList) FakeTupleSource(org.teiid.query.processor.FakeTupleSource) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager)

Example 45 with AggregateSymbol

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderBy(org.teiid.query.sql.lang.OrderBy) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) CommandContext(org.teiid.query.util.CommandContext) ArrayList(java.util.ArrayList) FakeTupleSource(org.teiid.query.processor.FakeTupleSource) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

AggregateSymbol (org.teiid.query.sql.symbol.AggregateSymbol)53 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)27 Test (org.junit.Test)21 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)16 ArrayList (java.util.ArrayList)12 List (java.util.List)11 Expression (org.teiid.query.sql.symbol.Expression)9 OrderBy (org.teiid.query.sql.lang.OrderBy)8 CommandContext (org.teiid.query.util.CommandContext)6 BufferManager (org.teiid.common.buffer.BufferManager)5 SymbolMap (org.teiid.query.sql.util.SymbolMap)5 BigDecimal (java.math.BigDecimal)4 FakeTupleSource (org.teiid.query.processor.FakeTupleSource)4 Constant (org.teiid.query.sql.symbol.Constant)4 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)3 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)3 AliasSymbol (org.teiid.query.sql.symbol.AliasSymbol)3 ExpressionSymbol (org.teiid.query.sql.symbol.ExpressionSymbol)3 Map (java.util.Map)2 AggregateFunction (org.teiid.query.function.aggregate.AggregateFunction)2