Author: shawkins
Date: 2012-08-14 13:45:39 -0400 (Tue, 14 Aug 2012)
New Revision: 4322
Modified:
branches/8.1.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
branches/8.1.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
branches/8.1.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
branches/8.1.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
Log:
TEIID-2146 fix for incorrect results with dependent join
Modified:
branches/8.1.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
---
branches/8.1.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2012-08-14
17:39:45 UTC (rev 4321)
+++
branches/8.1.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2012-08-14
17:45:39 UTC (rev 4322)
@@ -117,10 +117,10 @@
if (setState.maxNdv <= 0 || setState.maxNdv >= distinctCount)
{
continue;
}
- if (dvs.getTupleBuffer().getSchema().size() > 1) {
+ if (dvs.getTupleBuffer().getSchema().size() > 1 &&
dependentSetStates.size() > 1) {
distinctCount = 0;
ValueIterator vi = dvs.getValueIterator(setState.valueExpression);
- if
(dvs.getTupleBuffer().getSchema().indexOf(setState.valueExpression) == 0) {
+ if
(setState.valueExpression.equals(dependentSetStates.get(0).valueExpression)) {
Object last = null;
while (vi.hasNext()) {
Object next = vi.next();
Modified:
branches/8.1.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
===================================================================
---
branches/8.1.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2012-08-14
17:39:45 UTC (rev 4321)
+++
branches/8.1.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2012-08-14
17:45:39 UTC (rev 4322)
@@ -128,7 +128,7 @@
sortTypes.add(orderByItem.isAscending());
nullOrderings.add(orderByItem.getNullOrdering());
}
- if (items.size() < schema.size() && mode != Mode.SORT) {
+ if (items.size() < schema.size() && mode == Mode.DUP_REMOVE_SORT)
{
List<Expression> toAdd = new ArrayList<Expression>(schema);
toAdd.removeAll(sortElements);
sortElements.addAll(toAdd);
Modified:
branches/8.1.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
===================================================================
---
branches/8.1.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-08-14
17:39:45 UTC (rev 4321)
+++
branches/8.1.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-08-14
17:45:39 UTC (rev 4322)
@@ -1097,5 +1097,33 @@
List<? extends List<?>> vals =
s.getDependentValues().values().iterator().next();
assertEquals(1, vals.size());
}
+
+ @Test public void testIndependentDupRemoval() {
+ // Create query
+ String sql = "SELECT pm1.g1.e1, pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1
WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2<pm2.g1.e2 order by pm1.g1.e1 option makedep
pm1.g1"; //$NON-NLS-1$
+
+ // Create expected results
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] { "a", 0, 3 }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { "a", 0, 3 }), //$NON-NLS-1$
+ };
+
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
+ caps.setSourceProperty(Capability.MAX_DEPENDENT_PREDICATES, 1);
+ caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+
+ QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1Cached();
+
+ Command command = TestProcessor.helpParse(sql);
+ ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, new
DefaultCapabilitiesFinder(caps));
+
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ TestProcessor.sampleData1(dataManager);
+
+ // Run query
+ TestProcessor.helpProcess(plan, dataManager, expected);
+ }
}
Modified:
branches/8.1.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
===================================================================
---
branches/8.1.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java 2012-08-14
17:39:45 UTC (rev 4321)
+++
branches/8.1.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java 2012-08-14
17:45:39 UTC (rev 4322)
@@ -245,24 +245,16 @@
@Test public void testBasicSortRemoveDup() throws Exception {
List[] expected = new List[] {
Arrays.asList(new Object[] { new Integer(0), "0" }),
//$NON-NLS-1$
- Arrays.asList(new Object[] { new Integer(0), "3" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(1), "2" }),
//$NON-NLS-1$
- Arrays.asList(new Object[] { new Integer(1), "5" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(2), "1" }),
//$NON-NLS-1$
- Arrays.asList(new Object[] { new Integer(2), "4" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(3), "3" }),
//$NON-NLS-1$
- Arrays.asList(new Object[] { new Integer(3), "6" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(4), "3" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(5), "2" }),
//$NON-NLS-1$
- Arrays.asList(new Object[] { new Integer(5), "5" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(6), "1" }),
//$NON-NLS-1$
- Arrays.asList(new Object[] { new Integer(6), "4" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(7), "3" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(8), "2" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(9), "1" }),
//$NON-NLS-1$
- Arrays.asList(new Object[] { new Integer(9), "5" }),
//$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(10), "4" }),
//$NON-NLS-1$
- Arrays.asList(new Object[] { new Integer(10), "9" })
//$NON-NLS-1$
};
helpTestBasicSort(expected, Mode.DUP_REMOVE);