Author: shawkins
Date: 2012-01-18 15:04:59 -0500 (Wed, 18 Jan 2012)
New Revision: 3803
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
Log:
TEIID-1899 fixing assertion error during join
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
---
branches/7.6.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2012-01-18
16:10:12 UTC (rev 3802)
+++
branches/7.6.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2012-01-18
20:04:59 UTC (rev 3803)
@@ -83,6 +83,7 @@
private DependentValueSource dvs;
private List<SetState> dependentSetStates = new
LinkedList<SetState>();
private String valueSource;
+ private DependentValueSource originalVs;
public TupleState(String source) {
this.valueSource = source;
@@ -91,7 +92,7 @@
public void sort() throws BlockedException,
TeiidComponentException, TeiidProcessingException {
if (dvs == null) {
- DependentValueSource originalVs =
(DependentValueSource)dependentNode.getContext().getVariableContext().getGlobalValue(valueSource);
+ originalVs =
(DependentValueSource)dependentNode.getContext().getVariableContext().getGlobalValue(valueSource);
if (!originalVs.isDistinct()) {
if (sortUtility == null) {
List<SingleElementSymbol> sortSymbols = new
ArrayList<SingleElementSymbol>(dependentSetStates.size());
@@ -131,7 +132,9 @@
public void close() {
if (dvs != null) {
sortUtility = null;
- dvs.getTupleBuffer().remove();
+ if (dvs != originalVs) {
+ dvs.getTupleBuffer().remove();
+ }
dvs = null;
}
}
@@ -365,6 +368,11 @@
}
hasNextCommand = !restartIndexes.isEmpty();
+ if (hasNextCommand && dependentState.size() > 1) {
+ for (TupleState state : dependentState.values()) {
+ state.originalVs.setUnused(true);
+ }
+ }
}
protected boolean hasNextCommand() {
Modified:
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
===================================================================
---
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-01-18
16:10:12 UTC (rev 3802)
+++
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-01-18
20:04:59 UTC (rev 3803)
@@ -45,6 +45,7 @@
import org.teiid.query.sql.lang.Command;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.query.util.CommandContext;
+import org.teiid.translator.ExecutionFactory.NullOrder;
@SuppressWarnings({"unchecked", "nls"})
public class TestDependentJoins {
@@ -847,7 +848,47 @@
//note that the dependent join was performed
assertEquals(4, new HashSet<String>(dataManager.getQueries()).size());
}
+
+ @Test public void testIssue1899() throws Exception {
+ String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm3.g1 WHERE
pm1.g1.e1=pm3.g1.e1"; //$NON-NLS-1$
+ HardcodedDataManager dataManager = new HardcodedDataManager();
+ dataManager.addData("SELECT pm3.g1.e1 FROM pm3.g1 ORDER BY pm3.g1.e1",
new List<?>[] {Arrays.asList("a"), Arrays.asList("b"),
Arrays.asList("c")});
+ dataManager.addData("SELECT pm1.g1.e1 FROM pm1.g1", new List<?>[]
{Arrays.asList("a")});
+
+ TransformationMetadata fakeMetadata = RealMetadataFactory.example4();
+ fakeMetadata.getGroupID("pm1.g1").getAccessPatterns().clear();
+ RealMetadataFactory.setCardinality("pm1.g1", 1000, fakeMetadata);
+ fakeMetadata.getElementID("pm1.g1.e1").setDistinctValues(40);
+ RealMetadataFactory.setCardinality("pm3.g1", 1, fakeMetadata);
+ fakeMetadata.getElementID("pm3.g1.e1").setDistinctValues(1);
+ // Plan query
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
+ depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+ depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+ depcaps.setSourceProperty(Capability.QUERY_ORDERBY_DEFAULT_NULL_ORDER,
NullOrder.HIGH);
+
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+ caps.setSourceProperty(Capability.QUERY_ORDERBY_DEFAULT_NULL_ORDER,
NullOrder.HIGH);
+
+ capFinder.addCapabilities("pm3", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("pm1", depcaps); //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] {
+ new String("a")})}; //$NON-NLS-1$
+
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql, fakeMetadata, new String[] {
+ "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e1 IN (<dependent
values>)",
+ "SELECT pm3.g1.e1 FROM pm3.g1 ORDER BY pm3.g1.e1"
+ }, capFinder, ComparisonMode.EXACT_COMMAND_STRING);
+
+ // Run query
+ TestProcessor.helpProcess(plan, dataManager, expected);
+ }
+
private FakeDataManager helpTestBackoff(boolean setNdv) throws Exception,
QueryMetadataException, TeiidComponentException,
TeiidProcessingException {