Skip to content

Commit

Permalink
TEIID-5153 preventing removal from the original output columns
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Dec 1, 2017
1 parent 494ad7d commit 1498236
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Expand Up @@ -359,7 +359,7 @@ private PlanNode removeUnnecessaryInlineView(PlanNode root, PlanNode accessNode)
//will allow us to remove these views
if (child.getType() == NodeConstants.Types.PROJECT && child.getFirstChild() != null
&& child.getFirstChild().hasBooleanProperty(NodeConstants.Info.INLINE_VIEW)) {
List<Expression> requiredElements = (List<Expression>) child.getFirstChild().getProperty(Info.OUTPUT_COLS);
Set<Expression> requiredElements = new HashSet<Expression>((List<Expression>) child.getFirstChild().getProperty(Info.OUTPUT_COLS));
List<Expression> selectSymbols = (List<Expression>)child.getProperty(NodeConstants.Info.PROJECT_COLS);

// check that it only performs simple projection and that all required symbols are projected
Expand Down
31 changes: 31 additions & 0 deletions engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Expand Up @@ -7517,6 +7517,37 @@ private void sampleDataBQT2a(FakeDataManager dataMgr) throws Exception {
helpProcess(plan, cc, hdm, expected);
}

@Test
public void testPushdownInlineViewNotRemoved() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table test_a (a integer, b integer)", "x", "y");

BasicSourceCapabilities caps = getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, true);
caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
caps.setCapabilitySupport(Capability.QUERY_UNION, true);
CapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(caps);

String sql = "select CustomerType from (select 'a' as CustomerType, view1.* \n" +
" from (select min(a) as FirstOrderDate, count(b), b \n" +
" from (SELECT * FROM test_a) as pixiGetOrderHeader group by b) as NewCustomerTable, (SELECT * FROM test_a) view1 \n" +
" where view1.a = NewCustomerTable.b and view1.b = NewCustomerTable.FirstOrderDate \n" +
" UNION select 'Existing Customer' as CustomerType, view1.* \n" +
" from (select min(a) as FirstOrderDate, count(b), b \n" +
" from (SELECT * FROM test_a) view1 group by b) as NewCustomerTable, (SELECT * FROM test_a) view1 \n" +
" where view1.a = NewCustomerTable.b and view1.b != NewCustomerTable.FirstOrderDate) as view2";

ProcessorPlan plan = helpPlan(sql, metadata, //$NON-NLS-1
null, capFinder,
new String[] { "SELECT v_2.c_0 FROM (SELECT 'a' AS c_0, g_3.a AS c_1, g_3.b AS c_2 FROM (SELECT g_2.b AS c_0, MIN(g_2.a) AS c_1 FROM y.test_a AS g_2 GROUP BY g_2.b) AS v_1, y.test_a AS g_3 WHERE (g_3.a = v_1.c_0) AND (g_3.b = v_1.c_1) UNION SELECT 'Existing Customer' AS c_0, g_1.a AS c_1, g_1.b AS c_2 FROM (SELECT g_0.b AS c_0, MIN(g_0.a) AS c_1 FROM y.test_a AS g_0 GROUP BY g_0.b) AS v_0, y.test_a AS g_1 WHERE (g_1.a = v_0.c_0) AND (g_1.b <> v_0.c_1)) AS v_2" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$

CommandContext cc = createCommandContext();

HardcodedDataManager hdm = new HardcodedDataManager();
hdm.addData("SELECT v_2.c_0 FROM (SELECT 'a' AS c_0, g_3.a AS c_1, g_3.b AS c_2 FROM (SELECT g_2.b AS c_0, MIN(g_2.a) AS c_1 FROM y.test_a AS g_2 GROUP BY g_2.b) AS v_1, y.test_a AS g_3 WHERE (g_3.a = v_1.c_0) AND (g_3.b = v_1.c_1) UNION SELECT 'Existing Customer' AS c_0, g_1.a AS c_1, g_1.b AS c_2 FROM (SELECT g_0.b AS c_0, MIN(g_0.a) AS c_1 FROM y.test_a AS g_0 GROUP BY g_0.b) AS v_0, y.test_a AS g_1 WHERE (g_1.a = v_0.c_0) AND (g_1.b <> v_0.c_1)) AS v_2", Arrays.asList("a"));
helpProcess(plan, cc, hdm, new List<?>[] {Arrays.asList("a")} );
}

@Test public void testUncorrelatedScalarSubqueryPushdown1() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
Expand Down

0 comments on commit 1498236

Please sign in to comment.