Author: shawkins
Date: 2011-05-04 14:21:08 -0400 (Wed, 04 May 2011)
New Revision: 3151
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
Log:
TEIID-1577 fix for attempting to adjust union order by from the non-primary union branch
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java 2011-05-04
15:03:22 UTC (rev 3150)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java 2011-05-04
18:21:08 UTC (rev 3151)
@@ -228,7 +228,7 @@
if (frame.getFirstChild().getType() == NodeConstants.Types.TUPLE_LIMIT
&& NodeEditor.findParent(parentProject,
NodeConstants.Types.SORT |
NodeConstants.Types.DUP_REMOVE,
- NodeConstants.Types.SOURCE) != null) {
+ NodeConstants.Types.SOURCE |
NodeConstants.Types.SET_OP) != null) {
return root;
}
@@ -280,24 +280,24 @@
}
}
- PlanNode sort = NodeEditor.findParent(parentProject, NodeConstants.Types.SORT,
NodeConstants.Types.SOURCE);
- if (sort != null) { //special handling is needed since we are retaining the child
aliases
- List<SingleElementSymbol> childProject =
(List<SingleElementSymbol>)NodeEditor.findNodePreOrder(frame,
NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS);
- OrderBy elements = (OrderBy)sort.getProperty(NodeConstants.Info.SORT_ORDER);
- for (OrderByItem item : elements.getOrderByItems()) {
- item.setSymbol(childProject.get(selectSymbols.indexOf(item.getSymbol())));
- }
- sort.getGroups().clear();
- sort.addGroups(GroupsUsedByElementsVisitor.getGroups(elements));
+ if (parentProject.getParent() != null
+ && (parentProject.getParent().getType() != NodeConstants.Types.SET_OP
|| parentProject.getParent().getFirstChild() == parentProject)) {
+ PlanNode sort = NodeEditor.findParent(parentProject, NodeConstants.Types.SORT,
NodeConstants.Types.SOURCE);
+ if (sort != null) { //special handling is needed since we are retaining the
child aliases
+ List<SingleElementSymbol> childProject =
(List<SingleElementSymbol>)NodeEditor.findNodePreOrder(frame,
NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS);
+ OrderBy elements = (OrderBy)sort.getProperty(NodeConstants.Info.SORT_ORDER);
+ for (OrderByItem item : elements.getOrderByItems()) {
+ item.setSymbol(childProject.get(selectSymbols.indexOf(item.getSymbol())));
+ }
+ sort.getGroups().clear();
+ sort.addGroups(GroupsUsedByElementsVisitor.getGroups(elements));
+ }
+ PlanNode parentSource = NodeEditor.findParent(parentProject,
NodeConstants.Types.SOURCE);
+ if (parentSource != null) {
+
FrameUtil.correctSymbolMap(((SymbolMap)frame.getProperty(NodeConstants.Info.SYMBOL_MAP)).asMap(),
parentSource);
+ }
}
-
- PlanNode parentSource = NodeEditor.findParent(parentProject,
NodeConstants.Types.SOURCE);
-
- if (parentSource != null) {
-
FrameUtil.correctSymbolMap(((SymbolMap)frame.getProperty(NodeConstants.Info.SYMBOL_MAP)).asMap(),
parentSource);
- }
-
//remove the parent project and the source node
NodeEditor.removeChildNode(parentProject, frame);
if (parentProject.getParent() == null) {
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2011-05-04
15:03:22 UTC (rev 3150)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2011-05-04
18:21:08 UTC (rev 3151)
@@ -273,6 +273,22 @@
}, TestLimit.NODE_TYPES);
}
+ @Test public void testSimpleMergeUnionSecondBranchWithOrderBy() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+ caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+ caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+ caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ ProcessorPlan plan = TestOptimizer.helpPlan("select '1' as x, e2
from pm1.g1 union all select e1, e2 from (select e1, 1 as e2 from pm1.g2 limit 1) as x
order by x", //$NON-NLS-1$
+ FakeMetadataFactory.example1Cached(), null,
capFinder,
+ new String[] {"SELECT '1' AS c_0,
pm1.g1.e2 AS c_1 FROM pm1.g1 UNION ALL (SELECT pm1.g2.e1 AS c_0, 1 AS c_1 FROM pm1.g2
LIMIT 1) ORDER BY c_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+ TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+ }
+
/**
* Note that the merge is not performed since it would create an expression in the
group by clause
*/