Search in sources :

Example 81 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestWithClauseProcessing method testNestedWithRepeated.

@Test
public void testNestedWithRepeated() throws Exception {
    CommandContext cc = TestProcessor.createCommandContext();
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
    String sql = "begin WITH cte1 as (SELECT 1 as a), cte3 as (with cte3_1 as /*+ no_inline */ (select cte1.a from cte1 join pm1.g1 t1 on cte1.a=t1.e2) select * from cte3_1) SELECT * FROM cte3;" + " WITH cte1 as (SELECT 1 as a), cte3 as (with cte3_1 as /*+ no_inline */ (select cte1.a from cte1 join pm1.g1 t1 on cte1.a=t1.e2) select * from cte3_1) SELECT * FROM cte3; end";
    ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
    HardcodedDataManager hdm = new HardcodedDataManager(RealMetadataFactory.example1Cached());
    hdm.addData("WITH cte3_1 (a) AS (SELECT 1 FROM g1 AS g_0 WHERE g_0.e2 = 1) SELECT g_0.a FROM cte3_1 AS g_0", Arrays.asList(1));
    hdm.addData("WITH cte3_1__2 (a) AS (SELECT 1 FROM g1 AS g_0 WHERE g_0.e2 = 1) SELECT g_0.a FROM cte3_1__2 AS g_0", Arrays.asList(1));
    TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(1) });
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 82 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestWithClauseProcessing method testNestedWithCorrelatedPushdown.

/**
 * make sure that we don't pull up correlated
 * and that the references are correct
 * @throws Exception
 */
@Test
public void testNestedWithCorrelatedPushdown() 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.QUERY_SUBQUERIES_CORRELATED, true);
    bsc.setCapabilitySupport(Capability.SUBQUERY_COMMON_TABLE_EXPRESSIONS, true);
    bsc.setCapabilitySupport(Capability.QUERY_UNION, true);
    TransformationMetadata metadata = RealMetadataFactory.example1Cached();
    String sql = "select e1, e2 from pm1.g2 where e1 = (with g_0 as /*+ no_inline */ (SELECT pm1.g2.e1 from pm1.g1) select e1 from g_0)";
    ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(bsc), cc);
    HardcodedDataManager hdm = new HardcodedDataManager(metadata);
    hdm.addData("SELECT g_0.e1, g_0.e2 FROM g2 AS g_0 WHERE g_0.e1 = (WITH g_0__1 (e1) AS (SELECT g_0.e1 FROM g1 AS g_1) SELECT g_2.e1 FROM g_0__1 AS g_2)", Arrays.asList("a", 1), Arrays.asList("b", 2));
    TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList("a", 1), Arrays.asList("b", 2) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 83 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestWithClauseProcessing method testViewPlanningDeeplyNestedInlineRepeatedCTEName1.

@Test
public void testViewPlanningDeeplyNestedInlineRepeatedCTEName1() 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 varchar, b varchar); " + "	create view tv0 as WITH alias2 (a) AS (SELECT a FROM (SELECT 1 AS a) AS cte1) SELECT cte3.a FROM alias2 INNER JOIN (SELECT a FROM alias2) AS cte3 ON cte3.a = alias2.a;" + " create view tv1 as WITH cte1 as (SELECT a from test_a), alias2 as (select a from cte1), cte3 as (select a from alias2) SELECT cte3.a FROM alias2 join cte3 on cte3.a=alias2.a;" + " create view tv2 as WITH alias2 as (select b, a from test_a), cte4 as (select a from alias2) SELECT cte4.a FROM cte4 join alias2 on cte4.a=alias2.a ;", "x", "y");
    String sql = "with CTE1 as ( select a from ( with CTE11 as (select a from tv2) select a from CTE11 ) as  SUBQ1), CTE2 as ( select a from ( with CTE21 as (select a from tv2) select a from CTE21 ) as  SUBQ2) select T2.*, T1.* from CTE1 as T1 join CTE2 as T2 on T1.a=T2.a";
    ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(bsc), cc);
    HardcodedDataManager hdm = new HardcodedDataManager(metadata);
    hdm.addData("WITH alias2 (b, a) AS (SELECT NULL, g_0.a FROM test_a AS g_0) SELECT g_2.a, g_0.a FROM alias2 AS g_0, alias2 AS g_1, alias2 AS g_2, alias2 AS g_3 WHERE g_2.a = g_3.a AND g_0.a = g_1.a AND g_0.a = g_2.a", Arrays.asList(1, 1));
    TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(1, 1) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 84 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestWithClauseProcessing method testRecursiveWithPushdownNotFullyPushed.

@Test
public void testRecursiveWithPushdownNotFullyPushed() throws Exception {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // $NON-NLS-1$
    String sql = "WITH t(n, i) AS ( select 1,2 from pm1.g2 UNION ALL SELECT n+1, e2 FROM t, pm1.g1 WHERE n < 64 and pm1.g1.e2 = t.n ) SELECT * FROM t;";
    HardcodedDataManager dataManager = new HardcodedDataManager(RealMetadataFactory.example1Cached());
    dataManager.addData("SELECT g_0.e2 AS c_0 FROM g1 AS g_0 WHERE g_0.e2 < 64 AND g_0.e2 = 1 ORDER BY c_0", Arrays.asList(1));
    dataManager.addData("SELECT g_0.e2 AS c_0 FROM g1 AS g_0 WHERE g_0.e2 < 64 AND g_0.e2 = 2 ORDER BY c_0");
    dataManager.addData("SELECT 2 FROM g2 AS g_0", Arrays.asList(2));
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder, new String[] { "SELECT t.n, t.i FROM t" }, ComparisonMode.EXACT_COMMAND_STRING);
    CommandContext cc = createCommandContext();
    cc.setSession(new SessionMetadata());
    helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(1, 2), Arrays.asList(2, 1) });
    caps.setCapabilitySupport(Capability.RECURSIVE_COMMON_TABLE_EXPRESSIONS, true);
    plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder, new String[] { "SELECT t.n, t.i FROM t" }, ComparisonMode.EXACT_COMMAND_STRING);
    cc = createCommandContext();
    cc.setSession(new SessionMetadata());
    helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(1, 2), Arrays.asList(2, 1) });
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) Test(org.junit.Test)

Example 85 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestWithClauseProcessing method testNestedWith.

@Test
public void testNestedWith() throws Exception {
    CommandContext cc = TestProcessor.createCommandContext();
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
    String sql = "WITH cte1 as (SELECT 1 as a), cte3 as (with cte3_1 as (select cte1.a from cte1 join pm1.g1 t1 on cte1.a=t1.e2) select * from cte3_1) SELECT * FROM cte3";
    ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
    HardcodedDataManager hdm = new HardcodedDataManager(RealMetadataFactory.example1Cached());
    hdm.addData("SELECT 1 FROM g1 AS g_0 WHERE g_0.e2 = 1", Arrays.asList(1));
    TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(1) });
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

CommandContext (org.teiid.query.util.CommandContext)257 Test (org.junit.Test)179 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)104 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)95 List (java.util.List)90 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)64 ArrayList (java.util.ArrayList)44 Command (org.teiid.query.sql.lang.Command)38 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)37 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)26 Options (org.teiid.query.util.Options)20 BufferManager (org.teiid.common.buffer.BufferManager)19 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)19 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)18 TeiidProcessingException (org.teiid.core.TeiidProcessingException)14 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)13 BlockedException (org.teiid.common.buffer.BlockedException)11 TeiidComponentException (org.teiid.core.TeiidComponentException)11 Table (org.teiid.metadata.Table)11