teiid SVN: r4617 - in branches/7.7.x/engine/src: test/java/org/teiid/query/processor/relational and 1 other directory.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2013-11-21 15:27:31 -0500 (Thu, 21 Nov 2013)
New Revision: 4617
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
Log:
TEIID-2747: Wrong results with merge join SORT_DISTINCT with a full sort that is distinct beyond the join columns
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2013-11-20 21:21:24 UTC (rev 4616)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2013-11-21 20:27:31 UTC (rev 4617)
@@ -117,6 +117,7 @@
List<Expression> sortElements = null;
List<Boolean> sortTypes = null;
List<NullOrdering> nullOrderings = null;
+ int distinctIndex = -1;
if (items == null) {
sortElements = (List<Expression>) schema;
sortTypes = Collections.nCopies(sortElements.size(), OrderBy.ASC);
@@ -135,6 +136,9 @@
sortElements.addAll(toAdd);
sortTypes.addAll(Collections.nCopies(sortElements.size() - sortTypes.size(), OrderBy.ASC));
nullOrderings.addAll(Collections.nCopies(sortElements.size() - nullOrderings.size(), (NullOrdering)null));
+ //this path should be for join processing, which can check the isDistinct flag.
+ //that needs the proper index based upon the original sort columns, not based upon making the whole set distinct
+ distinctIndex = items.size() - 1;
}
}
@@ -147,6 +151,9 @@
}
init(sourceID, mode, bufferMgr, groupName, schema, sortTypes,
nullOrderings, cols);
+ if (distinctIndex != -1) {
+ this.comparator.setDistinctIndex(distinctIndex);
+ }
}
public SortUtility(TupleSource sourceID, Mode mode, BufferManager bufferMgr,
Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java 2013-11-20 21:21:24 UTC (rev 4616)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java 2013-11-21 20:27:31 UTC (rev 4617)
@@ -882,5 +882,64 @@
this.join.setJoinStrategy(joinStrategy);
helpTestJoinDirect(expected, 4, 1000);
}
+
+ @Test public void testSortMergeWithDistinct() throws TeiidComponentException, TeiidProcessingException {
+ this.leftTuples = new List[] {Arrays.asList(1, 2), Arrays.asList(1, 3)};
+ this.rightTuples = new List[] {Arrays.asList(1, 4), Arrays.asList(1, 5)};
+
+ expected = new List[] {
+ Arrays.asList(1, 2, 1, 4),
+ Arrays.asList(1, 2, 1, 5),
+ Arrays.asList(1, 3, 1, 4),
+ Arrays.asList(1, 3, 1, 5),
+ };
+ ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
+ es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+
+ ElementSymbol es2 = new ElementSymbol("e2"); //$NON-NLS-1$
+ es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+
+ List leftElements = Arrays.asList(es1, es2);
+ leftNode = new BlockingFakeRelationalNode(1, leftTuples);
+ leftNode.setElements(leftElements);
+
+ ElementSymbol es3 = new ElementSymbol("e3"); //$NON-NLS-1$
+ es3.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+
+ ElementSymbol es4 = new ElementSymbol("e4"); //$NON-NLS-1$
+ es4.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+
+ List rightElements = Arrays.asList(es3, es4);
+
+ rightNode = new BlockingFakeRelationalNode(2, rightTuples) {
+ @Override
+ public boolean hasBuffer(boolean requireFinal) {
+ return false;
+ }
+
+ @Override
+ public TupleBuffer getBuffer(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
+ fail();
+ throw new AssertionError();
+ };
+ };
+ rightNode.setElements(rightElements);
+
+ List joinElements = new ArrayList();
+ joinElements.addAll(leftElements);
+ joinElements.addAll(rightElements);
+
+ joinType = JoinType.JOIN_INNER;
+ joinStrategy = new MergeJoinStrategy(SortOption.SORT_DISTINCT, SortOption.SORT_DISTINCT, false);
+
+ join = new JoinNode(3);
+ join.setElements(joinElements);
+ join.setJoinType(joinType);
+
+ join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es3));
+ join.setJoinStrategy(joinStrategy);
+
+ helpTestJoinDirect(expected, 100, 100000);
+ }
}
Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java 2013-11-20 21:21:24 UTC (rev 4616)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java 2013-11-21 20:27:31 UTC (rev 4617)
@@ -316,6 +316,21 @@
assertEquals(Arrays.asList(2), ts.nextTuple());
}
+ @Test public void testDistinct() throws Exception {
+ ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
+ es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+ ElementSymbol es2 = new ElementSymbol("e2"); //$NON-NLS-1$
+ es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+ BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
+ TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es2), "test", TupleSourceType.PROCESSOR); //$NON-NLS-1$
+ tsid.addTuple(Arrays.asList(1, 1));
+ tsid.addTuple(Arrays.asList(1, 2));
+ tsid.close();
+ SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.DUP_REMOVE_SORT, bm, "test", tsid.getSchema()); //$NON-NLS-1$
+ su.sort();
+ assertFalse(su.isDistinct());
+ }
+
@Test public void testDupRemoveLowMemory() throws Exception {
ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);