Author: shawkins
Date: 2011-06-23 08:07:40 -0400 (Thu, 23 Jun 2011)
New Revision: 3260
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleAssignOutputElements.java
branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
Log:
TEIID-1645 fix for nested implicit grouping
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleAssignOutputElements.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleAssignOutputElements.java 2011-06-22
22:41:08 UTC (rev 3259)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleAssignOutputElements.java 2011-06-23
12:07:40 UTC (rev 3260)
@@ -162,6 +162,14 @@
assignOutputElements(root.getLastChild(), outputElements, metadata, capFinder,
rules, analysisRecord, context);
break;
case NodeConstants.Types.SOURCE: {
+ if (outputElements.isEmpty()) {
+ //we cannot completely filter an implicit grouping (this is a corner case)
+ PlanNode grouping = NodeEditor.findNodePreOrder(root.getFirstChild(),
NodeConstants.Types.GROUP, NodeConstants.Types.SOURCE | NodeConstants.Types.JOIN);
+ if (grouping != null &&
!grouping.hasCollectionProperty(NodeConstants.Info.GROUP_COLS)) {
+ SymbolMap symbolMap = (SymbolMap)
root.getProperty(NodeConstants.Info.SYMBOL_MAP);
+ outputElements.add(symbolMap.getKeys().get(0).clone());
+ }
+ }
outputElements = (List<SingleElementSymbol>)determineSourceOutput(root,
outputElements, metadata, capFinder);
root.setProperty(NodeConstants.Info.OUTPUT_COLS, outputElements);
List<SingleElementSymbol> childElements = filterVirtualElements(root,
outputElements, metadata);
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-06-22
22:41:08 UTC (rev 3259)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-06-23
12:07:40 UTC (rev 3260)
@@ -2357,16 +2357,6 @@
expression.setAggregateFunction(Type.MAX);
}
}
- if ((expression.getAggregateFunction() == Type.MAX ||
expression.getAggregateFunction() == Type.MIN)
- && EvaluatableVisitor.willBecomeConstant(expression.getExpression())) {
- try {
- return new ExpressionSymbol(expression.getName(), ResolverUtil
- .convertExpression(expression.getExpression(),DataTypeManager.getDataTypeName(expression.getType()),
metadata));
- } catch (QueryResolverException e) {
- //should not happen, so throw as a runtime
- throw new TeiidRuntimeException(e);
- }
- }
return expression;
}
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-06-22
22:41:08 UTC (rev 3259)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-06-23
12:07:40 UTC (rev 3260)
@@ -2122,7 +2122,7 @@
"SELECT MAX(sa.datevalue) FROM bqt1.smalla AS sb " + //$NON-NLS-1$
"WHERE (sb.intkey = sa.intkey) AND (sa.stringkey = sb.stringkey)
))"; //$NON-NLS-1$
- String sqlOut = "SELECT g_0.intkey FROM bqt1.smalla AS g_0 WHERE (g_0.intkey
= 46) AND (g_0.stringkey = '46') AND (g_0.datevalue = (SELECT g_0.datevalue FROM
bqt1.smalla AS g_1 WHERE (g_1.intkey = g_0.intkey) AND (g_1.stringkey =
g_0.stringkey)))"; //$NON-NLS-1$
+ String sqlOut = "SELECT g_0.intkey FROM bqt1.smalla AS g_0 WHERE (g_0.intkey
= 46) AND (g_0.stringkey = '46') AND (g_0.datevalue = (SELECT MAX(g_0.datevalue)
FROM bqt1.smalla AS g_1 WHERE (g_1.intkey = g_0.intkey) AND (g_1.stringkey =
g_0.stringkey)))"; //$NON-NLS-1$
ProcessorPlan plan = helpPlan(sqlIn,
RealMetadataFactory.exampleBQTCached(),
@@ -6587,6 +6587,26 @@
null, null, false); //$NON-NLS-1$
}
+ @Test public void testUnnamedAggInView() throws Exception {
+ MetadataStore metadataStore = new MetadataStore();
+
+ Schema bqt1 = RealMetadataFactory.createPhysicalModel("BQT1",
metadataStore); //$NON-NLS-1$
+ Schema vqt = RealMetadataFactory.createVirtualModel("VQT",
metadataStore); //$NON-NLS-1$
+
+ Table bqt1SmallA = RealMetadataFactory.createPhysicalGroup("SmallA",
bqt1); //$NON-NLS-1$
+ RealMetadataFactory.createElement("col", bqt1SmallA,
DataTypeManager.DefaultDataTypes.STRING);
+
+ Table agg3 = RealMetadataFactory.createVirtualGroup("Agg3", vqt, new
QueryNode("select count(*) from smalla"));
+ RealMetadataFactory.createElement("count", agg3,
DataTypeManager.DefaultDataTypes.INTEGER);
+
+ TransformationMetadata metadata =
RealMetadataFactory.createTransformationMetadata(metadataStore, "x");
+ BasicSourceCapabilities bac = getTypicalCapabilities();
+ bac.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+ bac.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+ bac.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+ helpPlan("select count(*) from agg3", metadata, new String[]
{"SELECT COUNT(*) FROM (SELECT COUNT(*) AS c_0 FROM BQT1.SmallA AS g_0) AS
v_0"}, new DefaultCapabilitiesFinder(bac), ComparisonMode.EXACT_COMMAND_STRING);
+ }
+
public static final boolean DEBUG = false;
}
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-06-22
22:41:08 UTC (rev 3259)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-06-23
12:07:40 UTC (rev 3260)
@@ -2086,7 +2086,7 @@
}
@Test public void testRewiteEvaluatableAggregate() {
- helpTestRewriteCommand("select pm1.g1.e1, max(1) from pm1.g1",
"SELECT pm1.g1.e1, 1 FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCommand("select max(1) from pm1.g1", "SELECT MAX(1)
FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testRewriteFromUnixTime() throws Exception {