Author: shawkins
Date: 2012-08-31 07:39:54 -0400 (Fri, 31 Aug 2012)
New Revision: 4386
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/PlanNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
Log:
TEIID-2178 correctly detecting subqueries in agg expressions
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/PlanNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/PlanNode.java 2012-08-30
18:55:26 UTC (rev 4385)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/PlanNode.java 2012-08-31
11:39:54 UTC (rev 4386)
@@ -30,6 +30,7 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants.Info;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.SubqueryContainer;
@@ -404,6 +405,11 @@
}
break;
}
+ case NodeConstants.Types.GROUP: {
+ SymbolMap groupMap = (SymbolMap)this.getProperty(Info.SYMBOL_MAP);
+ toSearch = groupMap.getValues();
+ break;
+ }
}
return ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(toSearch);
}
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java 2012-08-30
18:55:26 UTC (rev 4385)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java 2012-08-31
11:39:54 UTC (rev 4386)
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
@@ -47,6 +48,7 @@
import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.processor.BatchCollector.BatchProducer;
import org.teiid.query.processor.relational.SortUtility.Mode;
+import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.OrderBy;
import org.teiid.query.sql.lang.OrderByItem;
import org.teiid.query.sql.symbol.AggregateSymbol;
@@ -58,7 +60,7 @@
import org.teiid.query.util.CommandContext;
-public class GroupingNode extends RelationalNode {
+public class GroupingNode extends SubqueryAwareRelationalNode {
static class ProjectingTupleSource extends
BatchCollector.BatchProducerTupleSource {
@@ -106,7 +108,6 @@
private AggregateFunction[] functions;
private List<?> lastRow;
private List<?> currentGroupTuple;
- private Evaluator eval;
private static final int COLLECTION = 1;
private static final int SORT = 2;
@@ -324,11 +325,15 @@
public TupleSource getCollectionTupleSource() {
final RelationalNode sourceNode = this.getChildren()[0];
- return new ProjectingTupleSource(sourceNode, eval, new
ArrayList<Expression>(collectedExpressions.keySet()));
+ return new ProjectingTupleSource(sourceNode, getEvaluator(elementMap), new
ArrayList<Expression>(collectedExpressions.keySet()));
}
+
+ @Override
+ protected Collection<? extends LanguageObject> getObjects() {
+ return this.getChildren()[0].getOutputElements();
+ }
private void collectionPhase() {
- eval = new Evaluator(elementMap, getDataManager(), getContext());
if(this.orderBy == null) {
// No need to sort
this.groupTupleSource = getCollectionTupleSource();
Modified:
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2012-08-30
18:55:26 UTC (rev 4385)
+++
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2012-08-31
11:39:54 UTC (rev 4386)
@@ -141,7 +141,29 @@
// Run query
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testAggregateSubquery() throws Exception {
+ // Create query
+ String sql = "SELECT IntKey, SUM((select IntNum from bqt1.smallb where intkey =
smalla.intkey)) FROM BQT1.SmallA GROUP BY IntKey, IntNum HAVING IntNum > 10 ORDER BY
IntKey"; //$NON-NLS-1$
+ // Create expected results
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] { 1, 2l }),
+ Arrays.asList(new Object[] { 2, 3l }) };
+
+ // Construct data manager with data
+ HardcodedDataManager dataManager = new HardcodedDataManager();
+ dataManager.addData("SELECT g_0.IntKey, g_0.IntNum FROM BQT1.SmallA AS g_0 WHERE
g_0.IntNum > 10", new List<?>[] {Arrays.asList(1, 2), Arrays.asList(2,
3)});
+ dataManager.addData("SELECT g_0.IntNum FROM BQT1.SmallB AS g_0 WHERE g_0.IntKey =
1", new List<?>[] {Arrays.asList(2)});
+ dataManager.addData("SELECT g_0.IntNum FROM BQT1.SmallB AS g_0 WHERE g_0.IntKey =
2", new List<?>[] {Arrays.asList(3)});
+
+ // Plan query
+ ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.exampleBQTCached(),
TestOptimizer.getGenericFinder());
+
+ // Run query
+ helpProcess(plan, dataManager, expected);
+ }
+
@Test public void testAggregateOnBQT2() throws Exception {
// Create query
String sql = "SELECT IntNum, IsNotNull FROM (SELECT IntNum, LongNum, COUNT(IntNum)
AS IsNotNull FROM BQT1.SmallA GROUP BY IntNum, LongNum HAVING LongNum IS NULL ) AS x ORDER
BY IntNum, IsNotNull"; //$NON-NLS-1$