Author: shawkins
Date: 2012-02-21 21:54:36 -0500 (Tue, 21 Feb 2012)
New Revision: 3893
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
branches/7.7.x/engine/src/main/java/org/teiid/query/sql/lang/Select.java
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Log:
TEIID-1949 fix for assertionerror with sorting
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2012-02-20
02:38:50 UTC (rev 3892)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2012-02-22
02:54:36 UTC (rev 3893)
@@ -55,26 +55,7 @@
import org.teiid.query.processor.relational.RelationalPlan;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.rewriter.QueryRewriter;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.FromClause;
-import org.teiid.query.sql.lang.GroupBy;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.JoinPredicate;
-import org.teiid.query.sql.lang.JoinType;
-import org.teiid.query.sql.lang.Limit;
-import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.OrderByItem;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.lang.SetQuery.Operation;
import org.teiid.query.sql.navigator.DeepPostOrderNavigator;
import org.teiid.query.sql.symbol.AggregateSymbol;
@@ -263,6 +244,13 @@
}
PlanNode groupNode = NodeEditor.findNodePreOrder(node, NodeConstants.Types.GROUP,
NodeConstants.Types.SOURCE);
if (groupNode != null) {
+ if (query.getOrderBy() != null) {
+ query.setOrderBy(query.getOrderBy().clone());
+ }
+ if (query.getHaving() != null) {
+ query.setHaving((Criteria) query.getHaving().clone());
+ }
+ query.setSelect(query.getSelect().clone());
SymbolMap symbolMap = (SymbolMap)
groupNode.getProperty(NodeConstants.Info.SYMBOL_MAP);
//map back to expression form
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/sql/lang/Select.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/sql/lang/Select.java 2012-02-20
02:38:50 UTC (rev 3892)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/sql/lang/Select.java 2012-02-22
02:54:36 UTC (rev 3893)
@@ -197,7 +197,7 @@
* Return a deep copy of this Select.
* @return Deep clone
*/
- public Object clone() {
+ public Select clone() {
Select copy = new Select(LanguageObject.Util.deepClone(this.symbols,
SelectSymbol.class));
copy.setDistinct( isDistinct() );
return copy;
Modified:
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
---
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2012-02-20
02:38:50 UTC (rev 3892)
+++
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2012-02-22
02:54:36 UTC (rev 3893)
@@ -4106,7 +4106,32 @@
// Run query
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testPushedGroupingWithOrderBy() {
+ // Create query
+ final String sql = "SELECT e1, e2, count(*) as Count FROM pm1.g1 as DB GROUP
BY e1, e2 ORDER BY e1"; //$NON-NLS-1$
+
+ // Create expected results
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] { "a", 1, 2 }),
+ Arrays.asList(new Object[] { "b", 1, 2 }) //$NON-NLS-1$
+ };
+
+ // Construct data manager with data
+ HardcodedDataManager dataManager = new HardcodedDataManager();
+ dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2, COUNT(*) FROM pm1.g1 GROUP
BY pm1.g1.e1, pm1.g1.e2", new List<?>[] {Arrays.asList("b", 1, 2),
Arrays.asList("a", 1, 2)});
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities bsc = new BasicSourceCapabilities();
+ bsc.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+ bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+ capFinder.addCapabilities("pm1", bsc);
+ // Plan query
+ ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached(),
capFinder);
+ // Run query
+ helpProcess(plan, dataManager, expected);
+ }
+
/**
* Test <code>QueryProcessor</code>'s ability to process a query
containing
* an aggregate COUNT with a <code>CASE</code> expression in which a
Show replies by date