Author: shawkins
Date: 2011-07-27 13:32:30 -0400 (Wed, 27 Jul 2011)
New Revision: 3340
Added:
branches/7.4.x/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
Log:
TEIID-1683 fix for xml criteria planning with or across nested siblings
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java 2011-07-27
14:43:28 UTC (rev 3339)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java 2011-07-27
17:32:30 UTC (rev 3340)
@@ -66,6 +66,8 @@
//joined source node state
private int mappingClassNumber = 0;
private ElementSymbol mappingClassSymbol;
+ private boolean inputSet;
+ private boolean isCritNullDependent;
public ResultSetInfo(String resultName) {
this(resultName, false);
@@ -176,4 +178,20 @@
public boolean isStagedResult() {
return this.stagedResult;
}
+
+ public boolean hasInputSet() {
+ return inputSet;
+ }
+
+ public void setInputSet(boolean inputSet) {
+ this.inputSet = inputSet;
+ }
+
+ public void setCritNullDependent(boolean isCritNullDependent) {
+ this.isCritNullDependent = isCritNullDependent;
+ }
+
+ public boolean isCritNullDependent(){
+ return this.isCritNullDependent;
+ }
}
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java 2011-07-27
14:43:28 UTC (rev 3339)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java 2011-07-27
17:32:30 UTC (rev 3340)
@@ -37,6 +37,7 @@
import org.teiid.query.mapping.xml.MappingSourceNode;
import org.teiid.query.mapping.xml.ResultSetInfo;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.relational.rules.JoinUtil;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.symbol.Constant;
@@ -44,6 +45,7 @@
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
+import org.teiid.query.sql.visitor.GroupsUsedByElementsVisitor;
public class CriteriaPlanner {
@@ -106,9 +108,15 @@
//TODO: this can be replaced with method on the source node?
MappingSourceNode criteriaRs = findRootResultSetNode(context, sourceNodes,
criteria);
+ Collection<GroupSymbol> groups =
GroupsUsedByElementsVisitor.getGroups(conjunct);
+ boolean userCritNullDependent =
JoinUtil.isNullDependent(planEnv.getGlobalMetadata(), groups, conjunct);
+ ResultSetInfo rs = criteriaRs.getResultSetInfo();
+ if(userCritNullDependent){
+ rs.setCritNullDependent(true);
+ }
+
Criteria convertedCrit = XMLNodeMappingVisitor.convertCriteria(conjunct,
planEnv.mappingDoc, planEnv.getGlobalMetadata());
- ResultSetInfo rs = criteriaRs.getResultSetInfo();
rs.setCriteria(Criteria.combineCriteria(rs.getCriteria(), convertedCrit));
rs.addToCriteriaResultSets(sourceNodes);
}
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java 2011-07-27
14:43:28 UTC (rev 3339)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java 2011-07-27
17:32:30 UTC (rev 3340)
@@ -122,6 +122,7 @@
MappingSourceNode parent = sourceNode.getParentSourceNode();
Collection<ElementSymbol> bindings =
QueryUtil.getBindingElements(modifiedNode);
+ rsInfo.setInputSet(!bindings.isEmpty());
// root source nodes do not have any inputset criteria on them; so there is
no use in
// going through the raising the criteria.
// if the original query is not a select.. we are out of luck. we can expand
on this later
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2011-07-27
14:43:28 UTC (rev 3339)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2011-07-27
17:32:30 UTC (rev 3340)
@@ -300,9 +300,7 @@
Query currentQuery = contextQuery;
- for (Iterator i = resultSets.iterator(); i.hasNext();) {
- MappingSourceNode rsNode = (MappingSourceNode)i.next();
-
+ for (MappingSourceNode rsNode : resultSets) {
ResultSetInfo childRsInfo = rsNode.getResultSetInfo();
QueryNode planNode = QueryUtil.getQueryNode(childRsInfo.getResultSetName(),
planEnv.getGlobalMetadata());
@@ -313,35 +311,19 @@
updateSymbolMap(symbolMap, childRsInfo.getResultSetName(), inlineViewName,
planEnv.getGlobalMetadata());
// check if the criteria has been raised, if it is then we can update this as
a join.
- if (childRsInfo.isCriteriaRaised()) {
+ if (!rsInfo.isCritNullDependent() && childRsInfo.hasInputSet()
&& childRsInfo.isCriteriaRaised()) {
Query transformationQuery = (Query) command;
SubqueryFromClause sfc =
(SubqueryFromClause)transformationQuery.getFrom().getClauses().get(0);
Criteria joinCriteria = ((Query)childRsInfo.getCommand()).getCriteria();
- if (joinCriteria == null) {
- joinCriteria = QueryRewriter.TRUE_CRITERIA;
- }
-
joinCriteria = (Criteria)joinCriteria.clone();
//update the from clause
FromClause clause = currentQuery.getFrom().getClauses().remove(0);
- JoinPredicate join = null;
+ JoinPredicate join = new JoinPredicate(clause, sfc,
JoinType.JOIN_LEFT_OUTER, Criteria.separateCriteriaByAnd(joinCriteria));
- if (clause instanceof JoinPredicate) {
- join = (JoinPredicate)clause;
-
- FromClause right = join.getRightClause();
-
- JoinPredicate newRight = new JoinPredicate(right, sfc,
JoinType.JOIN_LEFT_OUTER, Criteria.separateCriteriaByAnd(joinCriteria));
-
- join.setRightClause(newRight);
- } else {
- join = new JoinPredicate(clause, sfc, JoinType.JOIN_LEFT_OUTER,
Criteria.separateCriteriaByAnd(joinCriteria));
- }
-
currentQuery.getFrom().addClause(join);
currentQuery.getSelect().setDistinct(true);
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java 2011-07-27
14:43:28 UTC (rev 3339)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java 2011-07-27
17:32:30 UTC (rev 3340)
@@ -154,6 +154,15 @@
return doc;
}
+ @Test public void testThreeWayOrWithNestedSiblings() throws Exception {
+ QueryMetadataInterface metadata =
TestXMLProcessor.exampleMetadataNestedWithSibling();
+ FakeDataManager dataMgr =
TestXMLProcessor.exampleDataManagerNestedWithSibling(metadata);
+ String resultFile =
"TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml";
//$NON-NLS-1$
+ String expectedDoc = TestXMLProcessor.readFile(resultFile);
+
+ TestXMLProcessor.helpTestProcess("select * from xmltest.doc9c where
itemid='003' or supplierid = '600' or orderid = '1'",
expectedDoc, metadata, dataMgr); //$NON-NLS-1$
+ }
+
@Test public void testBaseballPlayersDocDefect19541() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.exampleCase3225();
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-07-27
14:43:28 UTC (rev 3339)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-07-27
17:32:30 UTC (rev 3340)
@@ -606,7 +606,7 @@
return RealMetadataFactory.createTransformationMetadata(metadataStore,
"example1");
}
- public QueryMetadataInterface exampleMetadataNestedWithSibling() {
+ public static QueryMetadataInterface exampleMetadataNestedWithSibling() {
MetadataStore metadataStore = new MetadataStore();
// Create models
@@ -1231,7 +1231,7 @@
}
/** nested with sibling*/
- private MappingDocument createXMLPlanNested2c() {
+ private static MappingDocument createXMLPlanNested2c() {
MappingDocument doc = new MappingDocument(true);
MappingElement root = doc.addChildElement(new
MappingElement("Catalogs")); //$NON-NLS-1$
@@ -2256,7 +2256,7 @@
return dataMgr;
}
- private FakeDataManager exampleDataManagerNestedWithSibling(QueryMetadataInterface
metadata) {
+ static FakeDataManager exampleDataManagerNestedWithSibling(QueryMetadataInterface
metadata) {
FakeDataManager dataMgr = new FakeDataManager();
try {
Added:
branches/7.4.x/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml
===================================================================
---
branches/7.4.x/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml
(rev 0)
+++
branches/7.4.x/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml 2011-07-27
17:32:30 UTC (rev 3340)
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Catalogs>
+ <Catalog>
+ <Items>
+ <Item ItemID="001">
+ <Name>Lamp</Name>
+ <Quantity>5</Quantity>
+ <Suppliers>
+ <Supplier SupplierID="51">
+ <Name>Chucky</Name>
+ <Zip>11111</Zip>
+ </Supplier>
+ <Supplier SupplierID="52">
+ <Name>Biff's Stuff</Name>
+ <Zip>22222</Zip>
+ </Supplier>
+ <Supplier SupplierID="53">
+ <Name>AAAA</Name>
+ <Zip>33333</Zip>
+ </Supplier>
+ <Supplier SupplierID="56">
+ <Name>Microsoft</Name>
+ <Zip>66666</Zip>
+ </Supplier>
+ </Suppliers>
+ <Orders>
+ <Order OrderID="1">
+ <Name>KMart</Name>
+ <Zip>12345</Zip>
+ </Order>
+ <Order OrderID="2">
+ <Name>Sun</Name>
+ <Zip>94040</Zip>
+ </Order>
+ <Order OrderID="3">
+ <Name>Cisco</Name>
+ <Zip>94041</Zip>
+ </Order>
+ <Order OrderID="4">
+ <Name>Doc</Name>
+ <Zip>94042</Zip>
+ </Order>
+ </Orders>
+ </Item>
+ <Item ItemID="003">
+ <Name>Goat</Name>
+ <Quantity>4</Quantity>
+ <Suppliers>
+ <Supplier SupplierID="56">
+ <Name>Microsoft</Name>
+ <Zip>66666</Zip>
+ </Supplier>
+ </Suppliers>
+ <Orders>
+ <Order OrderID="7">
+ <Name>Inktomi</Name>
+ <Zip>94044</Zip>
+ </Order>
+ </Orders>
+ </Item>
+ </Items>
+ </Catalog>
+</Catalogs>
\ No newline at end of file
Property changes on:
branches/7.4.x/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain