Search in sources :

Example 61 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.

the class TestSubqueryPushdown method testSubqueryPlan.

@Test
public void testSubqueryPlan() throws Exception {
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    "select 1, (select cast(stringkey as integer) from bqt1.smallb where intkey = smalla.intkey) from bqt1.smalla", RealMetadataFactory.exampleBQTCached(), null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT g_0.IntKey FROM BQT1.SmallA AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    assertEquals(6, plan.getDescriptionProperties().getProperties().size());
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 62 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder 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)

Example 63 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.

the class TestSubqueryPushdown method testDeleteSubqueryCorrelatedCompensated.

@Test
public void testDeleteSubqueryCorrelatedCompensated() throws Exception {
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    "delete FROM pm1.g1 x where e1 = 'a' and e3 = (select e3 from pm1.g2 where e2 < x.e2)", RealMetadataFactory.example4(), null, new DefaultCapabilitiesFinder(bsc), new String[] {}, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager hcdm = new HardcodedDataManager();
    hcdm.addData("SELECT g_0.e3, g_0.e2, g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'a'", Arrays.asList(true, 1, 'a'));
    hcdm.addData("SELECT g_0.e3 FROM pm1.g2 AS g_0 WHERE g_0.e2 < 1", Arrays.asList(true));
    hcdm.addData("DELETE FROM pm1.g1 WHERE pm1.g1.e1 = 'a'", Arrays.asList(1));
    TestProcessor.helpProcess(plan, hcdm, null);
}
Also used : 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)

Example 64 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.

the class TestSubqueryPushdown method testCorrelatedOnly.

/**
 * Shows the uncorrelated subquery is evaluated ahead of time
 */
@Test
public void testCorrelatedOnly() throws Exception {
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
    bsc.setCapabilitySupport(Capability.QUERY_SUBQUERIES_ONLY_CORRELATED, true);
    bsc.setCapabilitySupport(Capability.CRITERIA_EXISTS, true);
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    "SELECT 1 FROM bqt1.smalla where EXISTS (SELECT 'Y' FROM bqt1.mediuma)", RealMetadataFactory.exampleBQTCached(), null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT 1 FROM BQT1.SmallA AS g_0 WHERE EXISTS (SELECT 'Y' FROM BQT1.MediumA AS g_0)" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager hcdm = new HardcodedDataManager(false);
    TestProcessor.helpProcess(plan, hcdm, null);
    assertEquals("SELECT 'Y' FROM BQT1.MediumA AS g_0", hcdm.getCommandHistory().get(0).toString());
    assertEquals("SELECT 1 FROM BQT1.SmallA AS g_0", hcdm.getCommandHistory().get(1).toString());
}
Also used : 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)

Example 65 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.

the class TestSubqueryPushdown method testSubuqeryOn2.

/**
 * Shows pushdown of on subquery with support
 */
@Test
public void testSubuqeryOn2() throws Exception {
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
    bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
    bsc.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, ExecutionFactory.SupportedJoinCriteria.ANY);
    bsc.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
    bsc.setCapabilitySupport(Capability.CRITERIA_EXISTS, true);
    bsc.setCapabilitySupport(Capability.QUERY_FROM_ANSI_JOIN, true);
    bsc.setCapabilitySupport(Capability.CRITERIA_ON_SUBQUERY, true);
    // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    "SELECT 1 FROM bqt1.smalla as Y93 LEFT OUTER JOIN bqt1.smallb as AG5 ON EXISTS (SELECT 'Y' FROM bqt1.mediuma WHERE AG5.intkey = 1 AND Y93.intkey = 1 )", RealMetadataFactory.exampleBQTCached(), null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT 1 FROM BQT1.SmallA AS g_0 LEFT OUTER JOIN BQT1.SmallB AS g_1 ON EXISTS (SELECT 'Y' FROM BQT1.MediumA AS g_2 WHERE (g_1.IntKey = 1) AND (g_0.IntKey = 1))" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)361 Test (org.junit.Test)344 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)277 List (java.util.List)121 CommandContext (org.teiid.query.util.CommandContext)95 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)89 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)87 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)42 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)41 Command (org.teiid.query.sql.lang.Command)23 CapabilitiesFinder (org.teiid.query.optimizer.capabilities.CapabilitiesFinder)17 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)15 ArrayList (java.util.ArrayList)13 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)13 PermissionMetaData (org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)13 Table (org.teiid.metadata.Table)12 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)7 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)7 TeiidComponentException (org.teiid.core.TeiidComponentException)6 TeiidProcessingException (org.teiid.core.TeiidProcessingException)6