teiid SVN: r1156 - in trunk/engine/src: test/java/com/metamatrix/query/optimizer and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-20 13:56:03 -0400 (Mon, 20 Jul 2009)
New Revision: 1156
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanUnions.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAccessPatterns.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAggregatePushdown.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestStoredProcedurePlanning.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestUnionPlanning.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java
Log:
TEIID-339 adding logic to raise union not all and to add distinct to push down queries under union not all.
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2009-07-20 17:46:42 UTC (rev 1155)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2009-07-20 17:56:03 UTC (rev 1156)
@@ -47,7 +47,6 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.lang.SetQuery.Operation;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.ElementSymbol;
@@ -346,8 +345,7 @@
for (PlanNode planNode : nodes) {
if (planNode.getType() == NodeConstants.Types.DUP_REMOVE
- || planNode.getProperty(NodeConstants.Info.SET_OPERATION).equals(Operation.UNION)
- && planNode.getProperty(NodeConstants.Info.USE_ALL).equals(Boolean.FALSE)) {
+ || (planNode.getType() == NodeConstants.Types.SET_OP && Boolean.FALSE.equals(planNode.getProperty(NodeConstants.Info.USE_ALL)))) {
return true;
}
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-07-20 17:46:42 UTC (rev 1155)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-07-20 17:56:03 UTC (rev 1156)
@@ -32,6 +32,7 @@
import com.metamatrix.query.analysis.AnalysisRecord;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
+import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
import com.metamatrix.query.optimizer.relational.OptimizerRule;
import com.metamatrix.query.optimizer.relational.RuleStack;
import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
@@ -95,6 +96,7 @@
}
plan = removeUnnecessaryInlineView(plan, commandRoot);
QueryCommand queryCommand = createQuery(metadata, capFinder, accessNode, commandRoot);
+ addSetOpDistinct(metadata, capFinder, accessNode, queryCommand);
command = queryCommand;
if (intoGroup != null) {
Insert insertCommand = new Insert(intoGroup, ResolverUtil.resolveElementsInGroup(intoGroup, metadata), null);
@@ -110,6 +112,33 @@
return plan;
}
+ private void addSetOpDistinct(QueryMetadataInterface metadata,
+ CapabilitiesFinder capFinder, PlanNode accessNode,
+ QueryCommand queryCommand) throws QueryMetadataException,
+ MetaMatrixComponentException {
+ if (queryCommand.getLimit() != null && queryCommand.getOrderBy() != null) {
+ return; //TODO: could create an inline view
+ }
+ PlanNode parent = accessNode.getParent();
+ boolean dupRemoval = false;
+ while (parent != null && parent.getType() == NodeConstants.Types.SET_OP) {
+ if (!parent.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
+ dupRemoval = true;
+ }
+ parent = parent.getParent();
+ }
+ if (!dupRemoval) {
+ return;
+ }
+ //TODO: we should also order the results and update the set processing logic
+ // this requires that we can guarantee null ordering
+ if (queryCommand instanceof SetQuery) {
+ ((SetQuery)queryCommand).setAll(false);
+ } else if (CapabilitiesUtil.supports(Capability.QUERY_SELECT_DISTINCT, RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder)) {
+ ((Query)queryCommand).getSelect().setDistinct(true);
+ }
+ }
+
private PlanNode removeUnnecessaryInlineView(PlanNode root, PlanNode accessNode) {
PlanNode child = accessNode.getFirstChild();
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanUnions.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanUnions.java 2009-07-20 17:46:42 UTC (rev 1155)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanUnions.java 2009-07-20 17:56:03 UTC (rev 1156)
@@ -169,7 +169,11 @@
MetaMatrixComponentException {
for (PlanNode child : unionNode.getChildren()) {
if (child.getType() == NodeConstants.Types.SET_OP) {
- if (all == child.hasBooleanProperty(NodeConstants.Info.USE_ALL) && setOp.equals(child.getProperty(NodeConstants.Info.SET_OPERATION)) && setOp != Operation.EXCEPT) { //keep collecting sources
+ if (!all && Operation.UNION == child.getProperty(NodeConstants.Info.SET_OPERATION)) {
+ //allow the parent to handle the dup removal
+ child.setProperty(NodeConstants.Info.USE_ALL, Boolean.TRUE);
+ }
+ if ((!all || child.hasBooleanProperty(NodeConstants.Info.USE_ALL)) && setOp.equals(child.getProperty(NodeConstants.Info.SET_OPERATION)) && setOp != Operation.EXCEPT) { //keep collecting sources
List accessNodes = NodeEditor.findAllNodes(child, NodeConstants.Types.ACCESS);
Object id = getModelId(metadata, accessNodes, capabilitiesFinder);
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAccessPatterns.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAccessPatterns.java 2009-07-20 17:46:42 UTC (rev 1155)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAccessPatterns.java 2009-07-20 17:56:03 UTC (rev 1156)
@@ -170,12 +170,12 @@
}
public void testUnionWithAccessPattern() {
- TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1 UNION select pm4.g1.e1 from pm4.g1 where pm4.g1.e1 = 'abc'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+ TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1 UNION ALL select pm4.g1.e1 from pm4.g1 where pm4.g1.e1 = 'abc'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm4.g1.e1 FROM pm4.g1 WHERE pm4.g1.e1 = 'abc'" }); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testUnionWithAccessPattern2() {
- TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1 UNION select pm4.g1.e1 from pm4.g1 where pm4.g1.e1 = 'abc' and pm4.g1.e2 = 1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+ TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1 UNION ALL select pm4.g1.e1 from pm4.g1 where pm4.g1.e1 = 'abc' and pm4.g1.e2 = 1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm4.g1.e1 FROM pm4.g1 WHERE (pm4.g1.e1 = 'abc') AND (pm4.g1.e2 = 1)" }); //$NON-NLS-1$ //$NON-NLS-2$
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAggregatePushdown.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAggregatePushdown.java 2009-07-20 17:46:42 UTC (rev 1155)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAggregatePushdown.java 2009-07-20 17:56:03 UTC (rev 1156)
@@ -22,6 +22,8 @@
package com.metamatrix.query.optimizer;
+import static com.metamatrix.query.optimizer.TestOptimizer.*;
+
import org.junit.Test;
import com.metamatrix.query.optimizer.TestOptimizer.ComparisonMode;
@@ -512,4 +514,237 @@
});
}
+ @Test public void testBusObjQuestion1() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
+
+ capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+ String sql = "SELECT Q1.S, Q2.C, Q1.PRODUCT, Q1.REGION AS Q1R, Q2.REGION AS Q2R FROM " + //$NON-NLS-1$
+ "(SELECT SUM(SALES) AS S, REGION, PRODUCT FROM DB2_TABLE WHERE PRODUCT IN ('GUNS', 'TOYS', 'VIDEOTAPES') GROUP BY REGION, PRODUCT) Q1 " + //$NON-NLS-1$
+ "FULL OUTER JOIN " + //$NON-NLS-1$
+ "(SELECT SUM(COSTS) AS C, REGION FROM ORACLE_TABLE WHERE YEAR = '1999' GROUP BY REGION) Q2 " + //$NON-NLS-1$
+ "ON Q1.REGION = Q2.REGION"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql,
+ metadata,
+ null, capFinder,
+ new String[] {"SELECT REGION, SUM(SALES), PRODUCT FROM db2model.DB2_TABLE WHERE PRODUCT IN ('GUNS', 'TOYS', 'VIDEOTAPES') GROUP BY REGION, PRODUCT", //$NON-NLS-1$
+ "SELECT REGION, SUM(COSTS) FROM oraclemodel.Oracle_table WHERE YEAR = '1999' GROUP BY REGION"}, //$NON-NLS-1$
+ SHOULD_SUCCEED );
+
+ checkNodeTypes(plan, new int[] {
+ 2, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 0, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 1, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ }
+
+ @Test public void testBusObjQuestion2() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
+
+ capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+ String sql = "SELECT SUM(F.SALES), G.REGION, T.YEAR " + //$NON-NLS-1$
+ "FROM SALES F, GEOGRAPHY G, msModel.TIME T " + //$NON-NLS-1$
+ "WHERE (F.CITY = G.CITY) AND (F.MONTH = T.MONTH) " + //$NON-NLS-1$
+ "AND G.REGION IN ('BORDEAUX', 'POLINESIA') AND T.YEAR = '1999' " + //$NON-NLS-1$
+ "GROUP BY G.REGION, T.YEAR"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql,
+ metadata,
+ null, capFinder,
+ new String[] {"SELECT g_0.MONTH, g_0.YEAR FROM msModel.\"TIME\" AS g_0 WHERE g_0.YEAR = '1999'", //$NON-NLS-1$
+ "SELECT g_0.MONTH AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.MONTH IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.MONTH, g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$
+ "SELECT g_0.CITY, g_0.REGION FROM oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX', 'POLINESIA')"}, //$NON-NLS-1$
+ ComparisonMode.EXACT_COMMAND_STRING );
+
+ checkNodeTypes(plan, new int[] {
+ 2, // Access
+ 1, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 1, // Grouping
+ 1, // NestedLoopJoinStrategy
+ 1, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ }
+
+ @Test public void testBusObjQuestion2Hint() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
+
+ capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+ String sql = "SELECT SUM(F.SALES), G.REGION, T.YEAR " + //$NON-NLS-1$
+ "FROM SALES F MAKEDEP, GEOGRAPHY G, msModel.TIME T " + //$NON-NLS-1$
+ "WHERE (F.CITY = G.CITY) AND (F.MONTH = T.MONTH) " + //$NON-NLS-1$
+ "AND G.REGION IN ('BORDEAUX', 'POLINESIA') AND T.YEAR = '1999' " + //$NON-NLS-1$
+ "GROUP BY G.REGION, T.YEAR"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql,
+ metadata,
+ null, capFinder,
+ new String[] {"SELECT g_0.MONTH, g_0.YEAR FROM msModel.\"TIME\" AS g_0 WHERE g_0.YEAR = '1999'", //$NON-NLS-1$
+ "SELECT g_0.MONTH AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.MONTH IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.MONTH, g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$
+ "SELECT g_0.CITY, g_0.REGION FROM oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX', 'POLINESIA')"}, //$NON-NLS-1$
+ ComparisonMode.EXACT_COMMAND_STRING );
+
+ checkNodeTypes(plan, new int[] {
+ 2, // Access
+ 1, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 1, // Grouping
+ 1, // NestedLoopJoinStrategy
+ 1, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ }
+
+ @Test public void testBusObjQuestion2HintVariation() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
+
+ capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+ String sql = "SELECT SUM(F.SALES), G.REGION, T.YEAR " + //$NON-NLS-1$
+ "FROM SALES F MAKEDEP, GEOGRAPHY2 G, msModel.TIME T " + //$NON-NLS-1$
+ "WHERE (F.CITY = G.CITY) AND (F.MONTH = T.MONTH) " + //$NON-NLS-1$
+ "AND G.REGION IN ('BORDEAUX', 'POLINESIA') AND T.YEAR = '1999' " + //$NON-NLS-1$
+ "GROUP BY G.REGION, T.YEAR"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql,
+ metadata,
+ null, capFinder,
+ new String[] {"SELECT g_0.MONTH AS c_0, g_1.REGION AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0, db2model.GEOGRAPHY2 AS g_1 WHERE (g_0.CITY = g_1.CITY) AND (g_1.REGION IN ('BORDEAUX', 'POLINESIA')) AND (g_0.MONTH IN (<dependent values>)) GROUP BY g_0.MONTH, g_1.REGION ORDER BY c_0", //$NON-NLS-1$
+ "SELECT g_0.MONTH AS c_0, g_0.YEAR AS c_1 FROM msModel.\"TIME\" AS g_0 WHERE g_0.YEAR = '1999' ORDER BY c_0"}, //$NON-NLS-1$
+ ComparisonMode.EXACT_COMMAND_STRING );
+
+ checkNodeTypes(plan, new int[] {
+ 1, // Access
+ 1, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 1, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 1, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ }
+
+ @Test public void testBusObjQuestion3() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
+
+ capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+ String sql = "select sum(c0), sum(b0), c1, b2 FROM db2Table, OraTable where c2=b2 group by c1, b2"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql,
+ metadata,
+ null, capFinder,
+ new String[] {"SELECT c2, c1, c0 FROM db2model.DB2TABLE", //$NON-NLS-1$
+ "SELECT b2, sum(b0) FROM oraclemodel.OraTable GROUP BY b2 ORDER BY b2"}, //$NON-NLS-1$
+ SHOULD_SUCCEED );
+
+ checkNodeTypes(plan, new int[] {
+ 2, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 1, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 1, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 2, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ }
+
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-07-20 17:46:42 UTC (rev 1155)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-07-20 17:56:03 UTC (rev 1156)
@@ -902,28 +902,28 @@
public void testPushingCriteriaThroughUnion1() {
helpPlan("select e1 from vm1.u1 where e1='abc'", example1(), //$NON-NLS-1$
new String[] { "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE pm1.g3.e1 = 'abc'", //$NON-NLS-1$
- "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
- "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
}
public void testPushingCriteriaThroughUnion2() {
helpPlan("select e1 from vm1.u2 where e1='abc'", example1(), //$NON-NLS-1$
- new String[] { "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
- "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+ new String[] { "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
}
public void testPushingCriteriaThroughUnion3() {
helpPlan("select e1 from vm1.u1 where e1='abc' and e2=5", example1(), //$NON-NLS-1$
new String[] { "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE (pm1.g3.e1 = 'abc') AND (pm1.g3.e2 = 5)", //$NON-NLS-1$
- "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') AND (pm1.g2.e2 = 5)", //$NON-NLS-1$
- "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') AND (pm1.g1.e2 = 5)" } ); //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') AND (pm1.g2.e2 = 5)", //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') AND (pm1.g1.e2 = 5)" } ); //$NON-NLS-1$
}
public void testPushingCriteriaThroughUnion4() {
helpPlan("select e1 from vm1.u1 where e1='abc' or e2=5", example1(), //$NON-NLS-1$
new String[] { "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE (pm1.g3.e1 = 'abc') OR (pm1.g3.e2 = 5)", //$NON-NLS-1$
- "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') OR (pm1.g1.e2 = 5)", //$NON-NLS-1$
- "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') OR (pm1.g2.e2 = 5)" } ); //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') OR (pm1.g1.e2 = 5)", //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') OR (pm1.g2.e2 = 5)" } ); //$NON-NLS-1$
}
// expression in a subquery of the union
@@ -992,8 +992,8 @@
ProcessorPlan plan = helpPlan("select vm1.u1.e1 from vm1.u1, pm1.g1 where vm1.u1.e1='abc' and vm1.u1.e1=pm1.g1.e1", example1(), //$NON-NLS-1$
new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'", //$NON-NLS-1$
"SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE pm1.g3.e1 = 'abc'", //$NON-NLS-1$
- "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
- "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
checkNodeTypes(plan, new int[] {
4, // Access
0, // DependentAccess
@@ -1137,8 +1137,8 @@
public void testDefect5283() {
helpPlan("select * from vm1.a6", example1(), //$NON-NLS-1$
- new String[] { "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", //$NON-NLS-1$
- "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2" } ); //$NON-NLS-1$
+ new String[] { "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", //$NON-NLS-1$
+ "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2" } ); //$NON-NLS-1$
}
public void testManyJoinsOverThreshold() throws Exception {
@@ -4789,239 +4789,6 @@
checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
-
- public void testBusObjQuestion1() {
- FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
-
- capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
- capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
- capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
-
- String sql = "SELECT Q1.S, Q2.C, Q1.PRODUCT, Q1.REGION AS Q1R, Q2.REGION AS Q2R FROM " + //$NON-NLS-1$
- "(SELECT SUM(SALES) AS S, REGION, PRODUCT FROM DB2_TABLE WHERE PRODUCT IN ('GUNS', 'TOYS', 'VIDEOTAPES') GROUP BY REGION, PRODUCT) Q1 " + //$NON-NLS-1$
- "FULL OUTER JOIN " + //$NON-NLS-1$
- "(SELECT SUM(COSTS) AS C, REGION FROM ORACLE_TABLE WHERE YEAR = '1999' GROUP BY REGION) Q2 " + //$NON-NLS-1$
- "ON Q1.REGION = Q2.REGION"; //$NON-NLS-1$
-
- ProcessorPlan plan = helpPlan(sql,
- metadata,
- null, capFinder,
- new String[] {"SELECT REGION, SUM(SALES), PRODUCT FROM db2model.DB2_TABLE WHERE PRODUCT IN ('GUNS', 'TOYS', 'VIDEOTAPES') GROUP BY REGION, PRODUCT", //$NON-NLS-1$
- "SELECT REGION, SUM(COSTS) FROM oraclemodel.Oracle_table WHERE YEAR = '1999' GROUP BY REGION"}, //$NON-NLS-1$
- SHOULD_SUCCEED );
-
- checkNodeTypes(plan, new int[] {
- 2, // Access
- 0, // DependentAccess
- 0, // DependentSelect
- 0, // DependentProject
- 0, // DupRemove
- 0, // Grouping
- 0, // NestedLoopJoinStrategy
- 1, // MergeJoinStrategy
- 0, // Null
- 0, // PlanExecution
- 1, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
- }
-
- public void testBusObjQuestion2() throws Exception {
- FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
-
- capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
- capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
- capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
-
- String sql = "SELECT SUM(F.SALES), G.REGION, T.YEAR " + //$NON-NLS-1$
- "FROM SALES F, GEOGRAPHY G, msModel.TIME T " + //$NON-NLS-1$
- "WHERE (F.CITY = G.CITY) AND (F.MONTH = T.MONTH) " + //$NON-NLS-1$
- "AND G.REGION IN ('BORDEAUX', 'POLINESIA') AND T.YEAR = '1999' " + //$NON-NLS-1$
- "GROUP BY G.REGION, T.YEAR"; //$NON-NLS-1$
-
- ProcessorPlan plan = helpPlan(sql,
- metadata,
- null, capFinder,
- new String[] {"SELECT g_0.MONTH, g_0.YEAR FROM msModel.\"TIME\" AS g_0 WHERE g_0.YEAR = '1999'", //$NON-NLS-1$
- "SELECT g_0.MONTH AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.MONTH IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.MONTH, g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$
- "SELECT g_0.CITY, g_0.REGION FROM oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX', 'POLINESIA')"}, //$NON-NLS-1$
- ComparisonMode.EXACT_COMMAND_STRING );
-
- checkNodeTypes(plan, new int[] {
- 2, // Access
- 1, // DependentAccess
- 0, // DependentSelect
- 0, // DependentProject
- 0, // DupRemove
- 1, // Grouping
- 1, // NestedLoopJoinStrategy
- 1, // MergeJoinStrategy
- 0, // Null
- 0, // PlanExecution
- 1, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
- }
-
- public void testBusObjQuestion2Hint() throws Exception {
- FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
-
- capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
- capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
- capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
-
- String sql = "SELECT SUM(F.SALES), G.REGION, T.YEAR " + //$NON-NLS-1$
- "FROM SALES F MAKEDEP, GEOGRAPHY G, msModel.TIME T " + //$NON-NLS-1$
- "WHERE (F.CITY = G.CITY) AND (F.MONTH = T.MONTH) " + //$NON-NLS-1$
- "AND G.REGION IN ('BORDEAUX', 'POLINESIA') AND T.YEAR = '1999' " + //$NON-NLS-1$
- "GROUP BY G.REGION, T.YEAR"; //$NON-NLS-1$
-
- ProcessorPlan plan = helpPlan(sql,
- metadata,
- null, capFinder,
- new String[] {"SELECT g_0.MONTH, g_0.YEAR FROM msModel.\"TIME\" AS g_0 WHERE g_0.YEAR = '1999'", //$NON-NLS-1$
- "SELECT g_0.MONTH AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.MONTH IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.MONTH, g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$
- "SELECT g_0.CITY, g_0.REGION FROM oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX', 'POLINESIA')"}, //$NON-NLS-1$
- ComparisonMode.EXACT_COMMAND_STRING );
-
- checkNodeTypes(plan, new int[] {
- 2, // Access
- 1, // DependentAccess
- 0, // DependentSelect
- 0, // DependentProject
- 0, // DupRemove
- 1, // Grouping
- 1, // NestedLoopJoinStrategy
- 1, // MergeJoinStrategy
- 0, // Null
- 0, // PlanExecution
- 1, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
- }
-
- public void testBusObjQuestion2HintVariation() throws Exception {
- FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
-
- capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
- capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
- capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
-
- String sql = "SELECT SUM(F.SALES), G.REGION, T.YEAR " + //$NON-NLS-1$
- "FROM SALES F MAKEDEP, GEOGRAPHY2 G, msModel.TIME T " + //$NON-NLS-1$
- "WHERE (F.CITY = G.CITY) AND (F.MONTH = T.MONTH) " + //$NON-NLS-1$
- "AND G.REGION IN ('BORDEAUX', 'POLINESIA') AND T.YEAR = '1999' " + //$NON-NLS-1$
- "GROUP BY G.REGION, T.YEAR"; //$NON-NLS-1$
-
- ProcessorPlan plan = helpPlan(sql,
- metadata,
- null, capFinder,
- new String[] {"SELECT g_0.MONTH AS c_0, g_1.REGION AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0, db2model.GEOGRAPHY2 AS g_1 WHERE (g_0.CITY = g_1.CITY) AND (g_1.REGION IN ('BORDEAUX', 'POLINESIA')) AND (g_0.MONTH IN (<dependent values>)) GROUP BY g_0.MONTH, g_1.REGION ORDER BY c_0", //$NON-NLS-1$
- "SELECT g_0.MONTH AS c_0, g_0.YEAR AS c_1 FROM msModel.\"TIME\" AS g_0 WHERE g_0.YEAR = '1999' ORDER BY c_0"}, //$NON-NLS-1$
- ComparisonMode.EXACT_COMMAND_STRING );
-
- checkNodeTypes(plan, new int[] {
- 1, // Access
- 1, // DependentAccess
- 0, // DependentSelect
- 0, // DependentProject
- 0, // DupRemove
- 1, // Grouping
- 0, // NestedLoopJoinStrategy
- 1, // MergeJoinStrategy
- 0, // Null
- 0, // PlanExecution
- 1, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
- }
-
- public void testBusObjQuestion3() {
- FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
-
- capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
- capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
- capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
-
- String sql = "select sum(c0), sum(b0), c1, b2 FROM db2Table, OraTable where c2=b2 group by c1, b2"; //$NON-NLS-1$
-
- ProcessorPlan plan = helpPlan(sql,
- metadata,
- null, capFinder,
- new String[] {"SELECT c2, c1, c0 FROM db2model.DB2TABLE", //$NON-NLS-1$
- "SELECT b2, sum(b0) FROM oraclemodel.OraTable GROUP BY b2 ORDER BY b2"}, //$NON-NLS-1$
- SHOULD_SUCCEED );
-
- checkNodeTypes(plan, new int[] {
- 2, // Access
- 0, // DependentAccess
- 0, // DependentSelect
- 0, // DependentProject
- 0, // DupRemove
- 1, // Grouping
- 0, // NestedLoopJoinStrategy
- 1, // MergeJoinStrategy
- 0, // Null
- 0, // PlanExecution
- 2, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
- }
public void testMultiUnionMergeVirtual() throws Exception {
String sql = "SELECT * FROM " + //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestStoredProcedurePlanning.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestStoredProcedurePlanning.java 2009-07-20 17:46:42 UTC (rev 1155)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestStoredProcedurePlanning.java 2009-07-20 17:56:03 UTC (rev 1156)
@@ -298,7 +298,7 @@
public void testStoredQuery22() {
ProcessorPlan plan = TestOptimizer.helpPlan("select e1 from (EXEC pm1.sq1()) as x where e1='a' union (select e1 from vm1.g2 where e1='b')", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
- new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'a'", "SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = 'b') AND (g_1.e1 = 'b')" }); //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] { "SELECT DISTINCT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'a'", "SELECT DISTINCT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = 'b') AND (g_1.e1 = 'b')" }); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestUnionPlanning.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestUnionPlanning.java 2009-07-20 17:46:42 UTC (rev 1155)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestUnionPlanning.java 2009-07-20 17:56:03 UTC (rev 1156)
@@ -73,7 +73,7 @@
capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT IntKey FROM BQT1.SmallA UNION SELECT IntNum FROM BQT2.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA", FakeMetadataFactory.exampleBQTCached(), null, capFinder,//$NON-NLS-1$
- new String[] { "SELECT IntNum FROM BQT2.SmallA", "SELECT IntKey FROM BQT1.SmallA", "SELECT IntNum FROM BQT1.SmallA" }, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new String[] { "SELECT DISTINCT IntNum FROM BQT2.SmallA", "SELECT DISTINCT IntKey FROM BQT1.SmallA", "SELECT IntNum FROM BQT1.SmallA" }, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
TestOptimizer.checkNodeTypes(plan, new int[] {
3, // Access
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java 2009-07-20 17:46:42 UTC (rev 1155)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java 2009-07-20 17:56:03 UTC (rev 1156)
@@ -35,7 +35,7 @@
public void testExcept() {
String sql = "select e1, e2 from pm1.g2 except select e1, 1 from pm1.g2"; //$NON-NLS-1$
- ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT DISTINCT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$
List<?>[] expected = new List[] {
Arrays.asList(new Object[] {"a", 0}), //$NON-NLS-1$
@@ -51,7 +51,7 @@
public void testIntersect() {
String sql = "select e1, e2 from pm1.g2 intersect select e1, 1 from pm1.g2"; //$NON-NLS-1$
- ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT DISTINCT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$
List<?>[] expected = new List[] {
Arrays.asList(new Object[] {null, 1}),
@@ -66,7 +66,7 @@
public void testIntersectExcept() {
String sql = "select e1, e2 from pm1.g2 except select e1, 1 from pm1.g2 intersect select 'a', e2 from pm1.g2"; //$NON-NLS-1$
- ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0", "SELECT g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT DISTINCT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0", "SELECT g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
List<?>[] expected = new List[] {
Arrays.asList(new Object[] {null, 1}),
16 years, 9 months
teiid SVN: r1155 - in trunk: client/src/main/java/com/metamatrix/common/comm/api and 6 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-07-20 13:46:42 -0400 (Mon, 20 Jul 2009)
New Revision: 1155
Added:
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java
Modified:
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/SQLStates.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java
trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
trunk/client-jdbc/src/main/resources/com/metamatrix/jdbc/basic_i18n.properties
trunk/client/src/main/java/com/metamatrix/common/api/MMURL.java
trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java
Log:
TEIID-725: Providing a mechanism in the "embedded" mode is shutdown the instance. This is similar to how derby does the "embedded" shutdown.
Modified: trunk/client/src/main/java/com/metamatrix/common/api/MMURL.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/api/MMURL.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client/src/main/java/com/metamatrix/common/api/MMURL.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -32,7 +32,7 @@
import com.metamatrix.common.comm.platform.CommPlatformPlugin;
/**
- * Class to encapsulate URL to a Clustered Metamatrix Server with multiple host
+ * Class defines the URL in the Teiid.
*
* @since 4.2
*/
@@ -62,6 +62,12 @@
* A plugable discovery strategy for the client. Defaults to using the AdminApi.
*/
public static final String DISCOVERY_STRATEGY = "discoveryStategy"; //$NON-NLS-1$
+
+ /**
+ * if "true" in the embedded mode if there is a active instance that instance will be shutdown.
+ */
+ public static final String SHUTDOWN = "shutdown"; //$NON-NLS-1$
+
public static final String SERVER_URL = "serverURL"; //$NON-NLS-1$
/**
* Non-secure MetaMatrix Protocol.
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -24,9 +24,6 @@
import java.util.Properties;
-import org.teiid.adminapi.Admin;
-import org.teiid.adminapi.AdminException;
-
import com.metamatrix.common.comm.exception.CommunicationException;
import com.metamatrix.common.comm.exception.ConnectionException;
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -27,6 +27,7 @@
import java.sql.SQLException;
import java.util.Properties;
+import com.metamatrix.common.api.MMURL;
import com.metamatrix.common.protocol.URLHelper;
/**
@@ -45,6 +46,8 @@
// string constant for the embedded configuration file property
public static final String DQP_BOOTSTRAP_FILE = "bootstrapFile"; //$NON-NLS-1$
+ public static final String SHUTDOWN = MMURL.CONNECTION.SHUTDOWN;
+
// The driver used to connect
private final transient EmbeddedDriver driver = new EmbeddedDriver();
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -56,6 +56,14 @@
super();
}
+ public MMSQLException(String reason) {
+ super(reason, SQLStates.DEFAULT);
+ }
+
+ public MMSQLException(String reason, String state) {
+ super(reason, state);
+ }
+
public static MMSQLException create(Throwable exception) {
if (exception instanceof MMSQLException) {
return (MMSQLException)exception;
@@ -63,6 +71,39 @@
return create(exception, exception.getMessage());
}
+ /**
+ * Constructor used to wrap metamatrix exceptions into MMSQLExceptions.
+ * @param reason String object which is the description of the exception.
+ * @param ex Throwable object which needs to be wrapped.
+ */
+ public MMSQLException(Throwable ex, String reason, String sqlState) {
+ super(reason, sqlState); // passing the message to the super class constructor.
+ initCause(ex);
+ }
+
+ /**
+ * Constructor used to wrap or copy a SQLException into a MMSQLException
+ * @see com.metamatrix.common.util.exception.SQLEXceptionUnroller
+ * @param ex
+ * @param message
+ * @param addChildren
+ */
+ private MMSQLException(SQLException ex, String message, boolean addChildren) {
+ super(message, ex.getSQLState() == null ? SQLStates.DEFAULT : ex.getSQLState(), ex.getErrorCode());
+
+ if (addChildren) {
+ SQLException childException = ex; // this a child to the SQLException constructed from reason
+
+ while (childException != null) {
+ if (childException instanceof MMSQLException) {
+ super.setNextException(ex);
+ break;
+ }
+ super.setNextException(new MMSQLException(childException, getMessage(childException, null),false));
+ childException = childException.getNextException();
+ }
+ }
+ }
public static MMSQLException create(Throwable exception, String message) {
message = getMessage(exception, message);
Throwable origException = exception;
@@ -79,7 +120,7 @@
exception = findRootException(exception);
sqlState = determineSQLState(exception, sqlState);
- return new MMSQLException(message, origException, sqlState);
+ return new MMSQLException(origException, message, sqlState);
}
/**
@@ -169,49 +210,8 @@
}
return message;
}
-
- /**
- * Constructor used to wrap metamatrix exceptions into MMSQLExceptions.
- * @param reason String object which is the description of the exception.
- * @param ex Throwable object which needs to be wrapped.
- */
- private MMSQLException(String reason, Throwable ex, String sqlState) {
- super(reason, sqlState); // passing the message to the super class constructor.
- initCause(ex);
- }
- /**
- * Constructor used to wrap or copy a SQLException into a MMSQLException
- * @see com.metamatrix.common.util.exception.SQLEXceptionUnroller
- * @param ex
- * @param message
- * @param addChildren
- */
- private MMSQLException(SQLException ex, String message, boolean addChildren) {
- super(message, ex.getSQLState() == null ? SQLStates.DEFAULT : ex.getSQLState(), ex.getErrorCode());
-
- if (addChildren) {
- SQLException childException = ex; // this a child to the SQLException constructed from reason
-
- while (childException != null) {
- if (childException instanceof MMSQLException) {
- super.setNextException(ex);
- break;
- }
- super.setNextException(new MMSQLException(childException, getMessage(childException, null),false));
- childException = childException.getNextException();
- }
- }
- }
- /**
- * Constructor a MMSQLException object initialized with reason.
- * @param reason String object which is the description of the exception.
- */
- public MMSQLException(String reason) {
- super(reason, SQLStates.DEFAULT);
- }
-
/**
* @see java.lang.Throwable#getCause()
* @since 4.3.2
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/SQLStates.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/SQLStates.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/SQLStates.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -100,6 +100,8 @@
// Class 38 - External Routine Exception (as defined by SQL spec):
/** External routine exception. This is the default unknown code */
public static final String DEFAULT = "38000"; //$NON-NLS-1$
+
+ public static final String SUCESS = "00000"; //$NON-NLS-1$
// Class 50 - Query execution errors
public static final SQLStateClass CLASS_USAGE_ERROR = new SQLStateClass("50"); //$NON-NLS-1$
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -62,7 +62,8 @@
ConnectionProperties.PROP_CLIENT_SESSION_PAYLOAD,
ConnectionProperties.PROP_CREDENTIALS,
MMURL.CONNECTION.AUTO_FAILOVER,
- MMURL.CONNECTION.DISCOVERY_STRATEGY
+ MMURL.CONNECTION.DISCOVERY_STRATEGY,
+ MMURL.CONNECTION.SHUTDOWN
};
private String vdbName;
Modified: trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
===================================================================
--- trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -42,6 +42,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.teiid.adminapi.Admin;
+import org.teiid.adminapi.AdminException;
+
import com.metamatrix.common.classloader.PostDelegatingClassLoader;
import com.metamatrix.common.comm.api.ServerConnection;
import com.metamatrix.common.comm.api.ServerConnectionFactory;
@@ -53,9 +56,11 @@
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
import com.metamatrix.jdbc.BaseDataSource;
+import com.metamatrix.jdbc.EmbeddedDataSource;
import com.metamatrix.jdbc.JDBCPlugin;
import com.metamatrix.jdbc.MMConnection;
import com.metamatrix.jdbc.MMSQLException;
+import com.metamatrix.jdbc.api.SQLStates;
import com.metamatrix.jdbc.util.MMJDBCURL;
@@ -90,7 +95,6 @@
*/
public static Connection connect(String url, Properties info)
throws SQLException {
- Connection conn = null;
// create a properties obj if it is null
if (info == null) {
info = new Properties();
@@ -100,8 +104,21 @@
// parse the URL to add it's properties to properties object
parseURL(url, info);
- conn = createConnection(info);
-
+ MMConnection conn = createConnection(info);
+ boolean shutdown = Boolean.parseBoolean(info.getProperty(EmbeddedDataSource.SHUTDOWN, "false")); //$NON-NLS-1$
+ if (shutdown) {
+ Admin admin = conn.getAdminAPI();
+ try {
+ // this will make sure the user has permissions to do the shutdown.
+ admin.shutdown(0);
+ shutdown();
+ throw new MMSQLException(getResourceMessage("EmbeddedDriver.shutdown_sucessful"), SQLStates.SUCESS); //$NON-NLS-1$
+ } catch (AdminException e) {
+ conn.close();
+ throw new MMSQLException(e, getResourceMessage("EmbeddedDriver.shutdown_failure"), SQLStates.DEFAULT); //$NON-NLS-1$
+ }
+ }
+
// logging
String logMsg = JDBCPlugin.Util.getString("JDBCDriver.Connection_sucess"); //$NON-NLS-1$
logger.fine(logMsg);
@@ -110,7 +127,7 @@
}
- static Connection createConnection(Properties info) throws SQLException{
+ static MMConnection createConnection(Properties info) throws SQLException{
// first validate the properties as this may called from the EmbeddedDataSource
// and make sure we have all the properties we need.
@@ -126,7 +143,7 @@
// now create the connection
EmbeddedTransport transport = getDQPTransport(dqpURL, info);
- Connection conn = transport.createConnection(dqpURL, info);
+ MMConnection conn = transport.createConnection(dqpURL, info);
return conn;
}
@@ -183,7 +200,7 @@
String connectionURL = jdbcURL.getConnectionURL();
if (connectionURL == null) {
connectionURL = getDefaultConnectionURL();
- info.setProperty("vdb.definition", jdbcURL.getVDBName()+".vdb"); //$NON-NLS-1$ //$NON-NLS-2$
+ info.setProperty(DQPEmbeddedProperties.VDB_DEFINITION, jdbcURL.getVDBName()+".vdb"); //$NON-NLS-1$
}
info.setProperty(DQPEmbeddedProperties.DQP_BOOTSTRAP_FILE, connectionURL);
@@ -399,7 +416,7 @@
* @param info
* @return Connection
*/
- Connection createConnection(URL url, Properties info) throws SQLException {
+ MMConnection createConnection(URL url, Properties info) throws SQLException {
ClassLoader current = null;
try {
current = Thread.currentThread().getContextClassLoader();
Modified: trunk/client-jdbc/src/main/resources/com/metamatrix/jdbc/basic_i18n.properties
===================================================================
--- trunk/client-jdbc/src/main/resources/com/metamatrix/jdbc/basic_i18n.properties 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/resources/com/metamatrix/jdbc/basic_i18n.properties 2009-07-20 17:46:42 UTC (rev 1155)
@@ -37,6 +37,8 @@
EmbeddedDriver.use_new_transport=Embedded driver is creating a new embedded service instance for create connection.
EmbeddedDriver.use_classpath=Embedded driver is using the following classpath to load the embedded service.
EmbeddedDriver.use_properties=Embedded driver is using the following properties to load the embedded service.
+EmbeddedDriver.shutdown_sucessful=Shutdown request successful.
+EmbeddedDriver.shutdown_failure=Shutdown request failed.
EmbeddedDataSource.Unable_to_load_MMDQP_Driver=Unable to load JDBC driver - check class path for jar files.
EmbeddedDataSource.The_configFile_property_is_null=The configFile property is null.
Added: trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java (rev 0)
+++ trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -0,0 +1,38 @@
+package com.metamatrix.server.integration;
+
+import java.sql.Connection;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+import com.metamatrix.core.util.UnitTestUtil;
+import com.metamatrix.jdbc.api.AbstractMMQueryTestCase;
+
+
+public class TestEmbeddedShutdown extends AbstractMMQueryTestCase {
+
+ private static final String DQP_PROP_FILE = UnitTestUtil.getTestDataPath() + "/authcheck/bqt.properties;"; //$NON-NLS-1$
+ private static final String VDB = "bqt"; //$NON-NLS-1$
+
+
+ @Test public void testShutdown() {
+ try {
+ Connection conn = getConnection(VDB, DQP_PROP_FILE, "user=admin;password=teiid;"); //$NON-NLS-1$
+ execute("select intkey, stringkey from BQT1.smalla"); //$NON-NLS-1$
+ walkResults();
+
+ try {
+ getConnection(VDB, DQP_PROP_FILE, "user=admin;password=teiid;shutdown=true"); //$NON-NLS-1$
+ TestCase.fail("should have failed to connect, as this is request for shutdown"); //$NON-NLS-1$
+ }catch(Exception e) {
+ //pass
+ }
+ if (!conn.isClosed()) {
+ TestCase.fail("should have closed"); //$NON-NLS-1$
+ }
+ } catch (Exception e) {
+ }
+ }
+
+}
Property changes on: trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 9 months
teiid SVN: r1154 - in trunk: engine/src/main/java/org/teiid/dqp/internal/datamgr/language and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-20 13:45:23 -0400 (Mon, 20 Jul 2009)
New Revision: 1154
Modified:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java
trunk/test-integration/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
Log:
TEIID-514 update of language bridge factory to not set the name of unrelated order by items, so that the element itself will be used by the connector.
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-07-20 16:00:33 UTC (rev 1153)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-07-20 17:45:23 UTC (rev 1154)
@@ -203,8 +203,8 @@
@Test
public void testDefect12120() {
helpTestVisitor(getBQTVDB(),
- "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE BQT1.SmallA.BooleanValue IN ({b'false'}, {b'true'}) ORDER BY IntKey", //$NON-NLS-1$
- "SELECT SmallA.IntKey FROM SmallA WHERE SmallA.BooleanValue IN (0, 1) ORDER BY IntKey"); //$NON-NLS-1$
+ "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE BQT1.SmallA.BooleanValue IN ({b'false'}, {b'true'})", //$NON-NLS-1$
+ "SELECT SmallA.IntKey FROM SmallA WHERE SmallA.BooleanValue IN (0, 1)"); //$NON-NLS-1$
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2009-07-20 16:00:33 UTC (rev 1153)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2009-07-20 17:45:23 UTC (rev 1154)
@@ -450,7 +450,11 @@
OrderByItemImpl orderByItem = null;
if(symbol instanceof ElementSymbol){
IElement innerElement = translate((ElementSymbol)symbol);
- orderByItem = new OrderByItemImpl(symbol.getOutputName(), direction, innerElement);
+ if (symbol.getOutputName() != null && symbol.getOutputName().indexOf(ElementSymbol.SEPARATOR) != -1) {
+ orderByItem = new OrderByItemImpl(null, direction, innerElement);
+ } else {
+ orderByItem = new OrderByItemImpl(symbol.getOutputName(), direction, innerElement);
+ }
} else {
orderByItem = new OrderByItemImpl(symbol.getOutputName(), direction, null);
}
Modified: trunk/test-integration/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2009-07-20 16:00:33 UTC (rev 1153)
+++ trunk/test-integration/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2009-07-20 17:45:23 UTC (rev 1154)
@@ -457,4 +457,26 @@
insert.setValueSource(command);
assertEquals("INSERT INTO g1 (e1, e2, e3, e4) SELECT g2.e1, g2.e2, g2.e3, g2.e4 FROM g2", insert.toString()); //$NON-NLS-1$
}
+
+ @Test public void testUnrelatedOrderBy() throws Exception {
+ String sql = "select intkey from bqt1.smalla order by stringkey"; //$NON-NLS-1$
+
+ ICommand command = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(sql, true, true);
+ assertEquals("SELECT g_0.IntKey AS c_0 FROM SmallA AS g_0 ORDER BY g_0.StringKey", command.toString()); //$NON-NLS-1$
+ }
+
+ @Test public void testOrderByDerivedColumn() throws Exception {
+ String sql = "select intkey as x from bqt1.smalla order by intkey"; //$NON-NLS-1$
+
+ ICommand command = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(sql, true, true);
+ assertEquals("SELECT g_0.IntKey AS c_0 FROM SmallA AS g_0 ORDER BY c_0", command.toString()); //$NON-NLS-1$
+ }
+
+ @Test public void testOrderByAlias() throws Exception {
+ String sql = "select intkey as x from bqt1.smalla order by x"; //$NON-NLS-1$
+
+ ICommand command = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(sql, true, true);
+ assertEquals("SELECT g_0.IntKey AS c_0 FROM SmallA AS g_0 ORDER BY c_0", command.toString()); //$NON-NLS-1$
+ }
+
}
16 years, 9 months