use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testSubqueryWithSemijoin.
@Test
public void testSubqueryWithSemijoin() throws Exception {
CommandContext cc = TestProcessor.createCommandContext();
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
bsc.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
String sql = "with eee as /*+ no_inline */ (select * from pm2.g1) select * from pm1.g2 where pm1.g2.e1 in (select e1 from eee)";
ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
HardcodedDataManager hdm = new HardcodedDataManager(RealMetadataFactory.example1Cached());
// we need the with associated with the subquery
hdm.addData("WITH eee (e1, e2, e3, e4) AS (SELECT g_0.e1, NULL, NULL, NULL FROM g1 AS g_0) SELECT g_0.e1 AS c_0 FROM eee AS g_0 ORDER BY c_0", Arrays.asList("a"), Arrays.asList("b"));
hdm.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM g2 AS g_0 WHERE g_0.e1 IN ('a', 'b') ORDER BY c_0", Arrays.asList("a", 1, 2.0, true), Arrays.asList("b", 2, 3.0, false));
TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList("a", 1, 2.0, true), Arrays.asList("b", 2, 3.0, false) });
sql = "with eee as (select * from pm2.g1) select * from pm1.g2 where pm1.g2.e1 in (select e1 from eee)";
plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
hdm = new HardcodedDataManager(RealMetadataFactory.example1Cached());
hdm.addData("SELECT g_0.e1, g_0.e2, g_0.e3, g_0.e4 FROM g2 AS g_0", Arrays.asList("a", 1, 2.0, true), Arrays.asList("b", 2, 3.0, false));
hdm.addData("SELECT g_0.e1 FROM g1 AS g_0", Arrays.asList("a"), Arrays.asList("b"));
TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList("a", 1, 2.0, true), Arrays.asList("b", 2, 3.0, false) });
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testViewPlanningDeeplyNested.
@Test
public void testViewPlanningDeeplyNested() throws Exception {
CommandContext cc = TestProcessor.createCommandContext();
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table test_a (a varchar); " + "create view tv1 as WITH alias as /*+ no_inline */ (SELECT a from test_a) " + ",alias2 as /*+ no_inline */ (select t2.a as a1, t1.a from alias t1 join (SELECT a from test_a) t2 on t1.a=t2.a) " + ",alias3 as /*+ no_inline */ (select t2.a as a1, t1.a from alias t1 join alias2 t2 on t1.a=t2.a) " + "SELECT alias.a as a1 FROM alias;", "x", "y");
String sql = "with CTE1 as /*+ no_inline */ ( select a1 from tv1), CTE2 as /*+ no_inline */ ( select a1 from tv1) select * from CTE1 as T1 join CTE1 as T2 on T1.a1=T2.a1";
ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(bsc), cc);
HardcodedDataManager hdm = new HardcodedDataManager(metadata);
hdm.addData("WITH alias (a) AS (SELECT g_0.a FROM test_a AS g_0), CTE1 (a1) AS (SELECT g_0.a FROM alias AS g_0) SELECT g_0.a1 AS c_0 FROM CTE1 AS g_0 ORDER BY c_0", Arrays.asList("a"));
TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList("a", "a") });
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testTupleBufferCacheAndWithClause.
@Test
public void testTupleBufferCacheAndWithClause() throws Exception {
CommandContext cc = TestProcessor.createCommandContext();
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
bsc.setCapabilitySupport(Capability.QUERY_UNION, true);
TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table test_a (a integer, b integer);", "x", "test");
String sql = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("cte-query.sql"));
ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(bsc), cc);
FakeDataManager fdm = new FakeDataManager();
fdm.registerTuples(metadata, "test_a", new List<?>[] { Arrays.asList(1, 1), Arrays.asList(3, 10) });
TestProcessor.helpProcess(plan, fdm, new List<?>[] { Arrays.asList(3, 3) });
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testMultiplePreviousReferencesInlined.
@Test
public void testMultiplePreviousReferencesInlined() throws Exception {
CommandContext cc = TestProcessor.createCommandContext();
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
String sql = "WITH cte1 as (SELECT e1, e2 from pm1.g1), cte2 as (select * from cte1), cte3 as (select * from cte1) " + "SELECT * FROM cte2 join cte3 on cte2.e1=cte3.e1";
ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
HardcodedDataManager hdm = new HardcodedDataManager(RealMetadataFactory.example1Cached());
// cte1 should appear once
hdm.addData("WITH cte1 (e1, e2) AS (SELECT g_0.e1, g_0.e2 FROM g1 AS g_0) SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM cte1 AS g_0 ORDER BY c_0", Arrays.asList("a", 1));
TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList("a", 1, "a", 1) });
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testSingleItemInOn.
@Test
public void testSingleItemInOn() {
// $NON-NLS-1$
String sql = "with a (x, y, z) as (select e1, e2, e3 from pm1.g1 limit 1) SELECT pm2.g1.e1 from pm2.g1 left outer join pm2.g2 on (pm2.g1.e2 = pm2.g2.e2 and pm2.g1.e1 = (select a.x from a))";
List[] expected = new List[] { Arrays.asList("a") };
HardcodedDataManager dataManager = new HardcodedDataManager() {
boolean block = true;
@Override
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
if (block) {
block = false;
throw BlockedException.INSTANCE;
}
return super.registerRequest(context, command, modelName, parameterObject);
}
};
dataManager.addData("SELECT g_0.e1 FROM pm1.g1 AS g_0", new List[] { Arrays.asList("a") });
dataManager.addData("SELECT g_0.e1 FROM pm2.g1 AS g_0 LEFT OUTER JOIN pm2.g2 AS g_1 ON g_0.e2 = g_1.e2 AND g_0.e1 = 'a'", new List[] { Arrays.asList("a") });
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
bsc.setCapabilitySupport(Capability.CRITERIA_ON_SUBQUERY, true);
ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc));
helpProcess(plan, dataManager, expected);
}
Aggregations