Search in sources :

Example 16 with CommandContext

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

the class TestSubqueryPushdown method testSubqueryRewriteToJoinDistinct1.

// won't rewrite since we need distinct and don't have all equi join predicates
@Test
public void testSubqueryRewriteToJoinDistinct1() throws Exception {
    CommandContext cc = new CommandContext();
    cc.setOptions(new Options().subqueryUnnestDefault(true));
    TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1 and e2 < x.e2)", "SELECT e1 FROM pm1.g1 AS x WHERE EXISTS (SELECT pm1.g1.e1 FROM pm1.g1 WHERE (e1 = x.e1) AND (e2 < x.e2) LIMIT 1)", RealMetadataFactory.example1Cached(), cc);
}
Also used : Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Example 17 with CommandContext

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

the class TestSubqueryPushdown method testDontRewriteToJoinWithOtherCriteria.

@Test
public void testDontRewriteToJoinWithOtherCriteria() throws Exception {
    CommandContext cc = new CommandContext();
    cc.setOptions(new Options().subqueryUnnestDefault(true));
    TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where pm3.g1.e1 in /*+ NO_UNNEST */ (select pm1.g1.e1 FROM pm1.g1 where e2 < pm3.g1.e2)", "SELECT e1 FROM pm3.g1 WHERE pm3.g1.e1 IN /*+ NO_UNNEST */ (SELECT pm1.g1.e1 FROM pm1.g1 WHERE e2 < pm3.g1.e2)", RealMetadataFactory.example4(), cc);
}
Also used : Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Example 18 with CommandContext

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

the class TestSubqueryPushdown method testPreEvaluationInAggregate1.

@Test
public void testPreEvaluationInAggregate1() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("x", new DDLHolder("my", "CREATE foreign TABLE test_b (b integer, c integer)"), new DDLHolder("pg", "CREATE foreign TABLE test_a (a integer, b integer); CREATE foreign TABLE test_only_pg (a integer, b integer);"));
    String sql = "SELECT SUM(x.b - (SELECT a FROM pg.test_only_pg WHERE b = 1)) FROM my.test_b x";
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
    bsc.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR_PROJECTION, true);
    bsc.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
    bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
    bsc.setFunctionSupport("-", true);
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    sql, tm, null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT SUM((g_0.b - (SELECT a FROM pg.test_only_pg WHERE b = 1 LIMIT 2))) FROM my.test_b AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager hdm = new HardcodedDataManager(tm);
    hdm.addData("SELECT g_0.a FROM test_only_pg AS g_0 WHERE g_0.b = 1", Arrays.asList(2));
    hdm.addData("SELECT SUM((g_0.b - 2)) FROM test_b AS g_0", Arrays.asList(Long.valueOf(3)));
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(tm);
    TestProcessor.helpProcess(plan, cc, hdm, new List[] { Arrays.asList(Long.valueOf(3)) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) DDLHolder(org.teiid.query.unittest.RealMetadataFactory.DDLHolder) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 19 with CommandContext

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

the class TestSubqueryPushdown method testSubqueryRewriteToJoin.

@Test
public void testSubqueryRewriteToJoin() throws Exception {
    CommandContext cc = new CommandContext();
    cc.setOptions(new Options().subqueryUnnestDefault(true));
    TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = pm3.g1.e1)", "SELECT e1 FROM pm3.g1, (SELECT e1 FROM pm1.g1) AS X__1 WHERE pm3.g1.e1 = X__1.e1", RealMetadataFactory.example4(), cc);
}
Also used : Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Example 20 with CommandContext

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

the class TestSubqueryPushdown method testNestedCorrelation.

@Test
public void testNestedCorrelation() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("CREATE foreign TABLE a (c1 integer, c2 integer); " + "CREATE foreign TABLE b (c3 integer, c4 integer); CREATE foreign TABLE c (c5 integer, c6 integer);", "x", "y");
    String sql = "SELECT (select c2 from b where c3 = (select c5 from c where c6 = c1)) FROM a group by c1, c2";
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    /*ProcessorPlan plan = TestOptimizer.helpPlan(sql, //$NON-NLS-1$
                                      tm, null, new DefaultCapabilitiesFinder(bsc),
                                      new String[] {
                                          "SELECT g_0.c1, g_0.c2 FROM y.a AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
        */
    HardcodedDataManager hdm = new HardcodedDataManager(tm);
    hdm.addData("SELECT g_0.c1, g_0.c2 FROM a AS g_0", Arrays.asList(1, 2));
    hdm.addData("SELECT g_0.c5 FROM c AS g_0 WHERE g_0.c6 = 1", Arrays.asList(1));
    hdm.addData("SELECT 2 FROM b AS g_0 WHERE g_0.c3 = 1", Arrays.asList(2));
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(tm);
    // TestProcessor.helpProcess(plan, cc, hdm, new List[] {Arrays.asList(2)} );
    // with conflicting aliases it should still work
    sql = "SELECT (select c2 from b where c3 = (select c5 from c as x where c6 = c1)) FROM a as x group by c1, c2";
    /*    plan = TestOptimizer.helpPlan(sql, //$NON-NLS-1$
                                      tm, null, new DefaultCapabilitiesFinder(bsc),
                                      new String[] {
                                          "SELECT g_0.c1, g_0.c2 FROM y.a AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
        
        TestProcessor.helpProcess(plan, cc, hdm, new List[] {Arrays.asList(2)} );
        */
    // with conflicting aliases it should still work
    sql = "SELECT (select c2 from b as x where c3 = (select c5 from c as x where c6 = c1)) FROM a as x group by c1, c2";
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    sql, tm, null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT g_0.c1, g_0.c2 FROM y.a AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    TestProcessor.helpProcess(plan, cc, hdm, new List[] { Arrays.asList(2) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) 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