use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testWithPushdownNestedInsert.
@Test
public void testWithPushdownNestedInsert() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
caps.setCapabilitySupport(Capability.INSERT_WITH_QUERYEXPRESSION, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
caps.setCapabilitySupport(Capability.SUBQUERY_COMMON_TABLE_EXPRESSIONS, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// $NON-NLS-1$
String sql = "insert into pm1.g1 (e1) with a (x) as /*+ no_inline */ (select e1 from pm1.g1) select a.x from a, a y";
List<?>[] expected = new List[] { Arrays.asList(1) };
HardcodedDataManager dataManager = new HardcodedDataManager(RealMetadataFactory.example1Cached());
dataManager.addData("INSERT INTO g1 (e1) WITH a (x) AS (SELECT g_0.e1 FROM g1 AS g_0) SELECT g_0.x FROM a AS g_0, a AS g_1", Arrays.asList(1));
CommandContext cc = TestProcessor.createCommandContext();
ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps), cc);
helpProcess(plan, cc, dataManager, expected);
// should be the same either way. up to the translator to deal with the with clause
caps.setCapabilitySupport(Capability.SUBQUERY_COMMON_TABLE_EXPRESSIONS, false);
cc = TestProcessor.createCommandContext();
plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps), cc);
helpProcess(plan, cc, dataManager, expected);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testProjectionMinimizationWithInlined.
@Test
public void testProjectionMinimizationWithInlined() throws Exception {
CommandContext cc = TestProcessor.createCommandContext();
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE foreign TABLE test_a(a integer, b integer)", "x", "y");
String sql = "with CTE1 as (WITH CTE11 as (SELECT a from test_a), CTE21 as (select t1.a from CTE11 t1 join CTE11 t2 on t1.a=t2.a), CTE31 as (select a from CTE21) SELECT CTE31.a FROM CTE21 join CTE31 on CTE31.a=CTE21.a ) select * from CTE1";
ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(bsc), cc);
HardcodedDataManager hdm = new HardcodedDataManager(metadata);
hdm.addData("WITH CTE11 (a) AS (SELECT g_0.a FROM test_a AS g_0), CTE21 (a) AS (SELECT g_0.a FROM CTE11 AS g_0, CTE11 AS g_1 WHERE g_0.a = g_1.a) SELECT g_1.a FROM CTE21 AS g_0, CTE21 AS g_1 WHERE g_1.a = g_0.a", Arrays.asList(1));
TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(1) });
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testWithAggregation1.
@Test
public void testWithAggregation1() throws Exception {
String sql = "WITH x as /*+ no_inline */ (SELECT e1 FROM pm1.g1) SELECT p.e1, SUM(max(p.e2)) OVER (partition by p.e1) as y FROM pm1.g1 p JOIN x ON x.e1 = p.e1 GROUP BY p.e1";
HardcodedDataManager dataManager = new HardcodedDataManager(RealMetadataFactory.example1Cached());
dataManager.addData("SELECT g_0.e1 FROM g1 AS g_0", Arrays.asList("a"), Arrays.asList("b"), Arrays.asList("a"));
dataManager.addData("SELECT g_0.e1, g_0.e2 FROM g1 AS g_0 WHERE g_0.e1 IN ('a', 'b')", Arrays.asList("a", 1), Arrays.asList("a", 2), Arrays.asList("b", 3));
CommandContext cc = TestProcessor.createCommandContext();
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
List<?>[] expected = new List[] { Arrays.asList("a", 2l), Arrays.asList("b", 3l) };
helpProcess(plan, cc, dataManager, expected);
// full push down
cc = TestProcessor.createCommandContext();
bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
bsc.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true);
bsc.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
TestOptimizer.checkAtomicQueries(new String[] { "WITH x (e1) AS /*+ no_inline */ (SELECT g_0.e1 FROM pm1.g1 AS g_0) SELECT g_0.e1, SUM(MAX(g_0.e2)) OVER (PARTITION BY g_0.e1) FROM pm1.g1 AS g_0, x AS g_1 WHERE g_1.e1 = g_0.e1 GROUP BY g_0.e1" }, plan);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testPullupNestedSubquery1.
@Test
public void testPullupNestedSubquery1() throws Exception {
CommandContext cc = TestProcessor.createCommandContext();
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
bsc.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
bsc.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
bsc.setCapabilitySupport(Capability.QUERY_UNION, true);
bsc.setCapabilitySupport(Capability.ROW_LIMIT, true);
bsc.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
bsc.setCapabilitySupport(Capability.SUBQUERY_COMMON_TABLE_EXPRESSIONS, true);
TransformationMetadata metadata = RealMetadataFactory.example1Cached();
String sql = "with CTE1 as (SELECT e1 from pm1.g1) select distinct e1 from (select * from pm1.g2 where e1 in (select e1 from CTE1) order by e1 limit 10) x union all select e1 from pm1.g3 where e1 in (select e1 from CTE1)";
ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(bsc), cc);
HardcodedDataManager hdm = new HardcodedDataManager(metadata);
hdm.addData("WITH CTE1 (e1) AS (SELECT g_0.e1 FROM g1 AS g_0) SELECT DISTINCT v_0.c_0 FROM (SELECT g_2.e1 AS c_0 FROM g2 AS g_2 WHERE g_2.e1 IN (SELECT g_3.e1 FROM CTE1 AS g_3) ORDER BY c_0 LIMIT 10) AS v_0 UNION ALL SELECT g_0.e1 AS c_0 FROM g3 AS g_0 WHERE g_0.e1 IN (SELECT g_1.e1 FROM CTE1 AS g_1)", Arrays.asList("a"));
TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList("a") });
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testRecursiveUnion.
@Test
public void testRecursiveUnion() throws Exception {
// $NON-NLS-1$
String sql = "WITH t(n) AS ( (VALUES (1) union all values(2)) UNION (SELECT n+1 FROM t WHERE n < 64 union all SELECT e2 from pm1.g1) ) SELECT sum(n) FROM t;";
List<?>[] expected = new List[] { Arrays.asList(2080l) };
FakeDataManager dataManager = new FakeDataManager();
dataManager.setBlockOnce();
sampleData1(dataManager);
ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached());
CommandContext cc = createCommandContext();
cc.setSession(new SessionMetadata());
helpProcess(plan, cc, dataManager, expected);
}
Aggregations