Skip to content

Commit

Permalink
TEIID-4237 correcting the distinct flag detection
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jun 1, 2016
1 parent da078da commit ffc9367
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Expand Up @@ -254,7 +254,7 @@ static boolean insertSort(PlanNode childNode, List<Expression> expressions, Plan
if (sourceNode.getFirstChild() != null && sourceNode.getType() == NodeConstants.Types.SOURCE && outputSymbols.size() == expressions.size() && outputSymbols.containsAll(expressions)) {
PlanNode setOp = NodeEditor.findNodePreOrder(sourceNode.getFirstChild(), NodeConstants.Types.SET_OP, NodeConstants.Types.SOURCE);
if (setOp != null) {
if (setOp.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
if (!setOp.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
distinct = true;
}
} else if (NodeEditor.findNodePreOrder(sourceNode.getFirstChild(), NodeConstants.Types.DUP_REMOVE, NodeConstants.Types.PROJECT) != null) {
Expand Down
Expand Up @@ -24,6 +24,7 @@

import static org.junit.Assert.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -37,6 +38,7 @@
import org.teiid.metadata.Column;
import org.teiid.metadata.KeyRecord.Type;
import org.teiid.metadata.Table;
import org.teiid.query.function.FunctionMethods;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
Expand Down Expand Up @@ -1282,4 +1284,32 @@ private void helpTestNullDependent(String expressionSQL,

TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(1, "2", 1)});
}

@Test public void testDistinctDetectionWithUnionAll() throws Exception {
String sql = "select avg(t1.a) from (select 3 as a, 3 as b union all "
+ "select 1 as a, 1 as b union all select 3 as a, 3 as b) as t1 "
+ "join (select 1 as a, 1 as b union all select 1 as a, 1 as b union all "
+ "select 2 as a, 2 as b union all select 2 as a, 2 as b union all "
+ "select 3 as a, 3 as b union all select 3 as a, 3 as b) as t2 on t1.a=t2.a";

TransformationMetadata metadata = RealMetadataFactory.example1Cached();
HardcodedDataManager hdm = new HardcodedDataManager();
ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata);

TestProcessor.helpProcess(plan, TestProcessor.createCommandContext(), hdm, new List<?>[] { Arrays.asList(FunctionMethods.divide(BigDecimal.valueOf(14), BigDecimal.valueOf(6))) });
}

@Test public void testDistinctDetectionWithUnion() throws Exception {
String sql = "select avg(t1.a) from (select 3 as a, 3 as b union "
+ "select 1 as a, 1 as b union select 3 as a, 3 as b) as t1 "
+ "join (select 1 as a, 1 as b union all select 1 as a, 1 as b union all "
+ "select 2 as a, 2 as b union all select 2 as a, 2 as b union all "
+ "select 3 as a, 3 as b union all select 3 as a, 3 as b) as t2 on t1.a=t2.a";

TransformationMetadata metadata = RealMetadataFactory.example1Cached();
HardcodedDataManager hdm = new HardcodedDataManager();
ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata);

TestProcessor.helpProcess(plan, TestProcessor.createCommandContext(), hdm, new List<?>[] { Arrays.asList(BigDecimal.valueOf(2)) });
}
}

0 comments on commit ffc9367

Please sign in to comment.