Author: shawkins
Date: 2011-06-03 22:46:06 -0400 (Fri, 03 Jun 2011)
New Revision: 3217
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
Log:
TEIID-1621 fix for aggregate decomposition issue
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2011-06-03
20:17:30 UTC (rev 3216)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2011-06-04
02:46:06 UTC (rev 3217)
@@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
@@ -540,20 +541,19 @@
}
Map<PlanNode, List<SingleElementSymbol>> groupingMap =
createNodeMapping(groupNode, groupingExpressions, false);
- Set<PlanNode> possibleTargetNodes = new
HashSet<PlanNode>(aggregateMap.keySet());
+ Set<PlanNode> possibleTargetNodes = new
LinkedHashSet<PlanNode>(aggregateMap.keySet());
possibleTargetNodes.addAll(groupingMap.keySet());
for (PlanNode planNode : possibleTargetNodes) {
Set<SingleElementSymbol> stagedGroupingSymbols = new
LinkedHashSet<SingleElementSymbol>();
List<AggregateSymbol> aggregates = aggregateMap.get(planNode);
- List<SingleElementSymbol> groupBy = groupingMap.get(planNode);
if (!canPush(groupNode, stagedGroupingSymbols, planNode)) {
continue;
}
- if (groupBy != null) {
- stagedGroupingSymbols.addAll(groupBy);
+ if (groupingExpressions != null) {
+ filterJoinColumns(stagedGroupingSymbols, planNode.getGroups(),
groupingExpressions);
}
collectSymbolsFromOtherAggregates(allAggregates, aggregates, planNode,
stagedGroupingSymbols);
@@ -715,7 +715,7 @@
private <T extends SingleElementSymbol> Map<PlanNode, List<T>>
createNodeMapping(PlanNode groupNode,
Collection<T> expressions, boolean aggs) {
- Map<PlanNode, List<T>> result = new HashMap<PlanNode,
List<T>>();
+ Map<PlanNode, List<T>> result = new LinkedHashMap<PlanNode,
List<T>>();
if (expressions == null) {
return result;
}
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2011-06-03
20:17:30 UTC (rev 3216)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2011-06-04
02:46:06 UTC (rev 3217)
@@ -40,7 +40,7 @@
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.translator.SourceSystemFunctions;
-@SuppressWarnings("nls")
+@SuppressWarnings({"nls", "unchecked"})
public class TestAggregateProcessing {
static void sampleDataBQT3(FakeDataManager dataMgr) throws Exception {
@@ -219,7 +219,6 @@
helpProcess(plan, dataManager, expected);
}
- @SuppressWarnings("unchecked")
@Test public void testAggregatePushdown() {
Command command = helpParse("select e1, count(e2), max(e2) from (select e1, e2,
e3 from pm1.g1 union all select e1, e2, e3 from pm1.g2 union all select e1, e2, e3 from
pm2.g1) z group by e1"); //$NON-NLS-1$
@@ -349,5 +348,29 @@
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testJira1621() throws Exception {
+ // Create query
+ String sql = "SELECT sum(t2.e4) as s, max(t1.e1 || t2.e1) FROM pm1.g1 as t1,
pm1.g2 as t2, pm1.g3 as t3 WHERE t1.e1 = coalesce(t2.e1, 'b') AND t2.e2 = t3.e2
GROUP BY t2.e2, t2.e3, t3.e2 ORDER BY s"; //$NON-NLS-1$
+ // Create expected results
+ List[] expected = new List[] {
+ Arrays.asList(null, "cc"),
+ Arrays.asList(0.0, "bb"),
+ Arrays.asList(1.0, null),
+ Arrays.asList(2.0, "aa"),
+ Arrays.asList(7.0, "aa")
+ };
+
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ // Plan query
+ ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached());
+
+ // Run query
+ helpProcess(plan, dataManager, expected);
+ }
+
}