Search in sources :

Example 36 with DefaultCapabilitiesFinder

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

the class TestSortOptimization method testProjectionRaisingWithLimit1.

@Test
public void testProjectionRaisingWithLimit1() {
    // Create query
    // $NON-NLS-1$
    String sql = "select (select e1 from pm2.g1 where e2 = x.e2) as z from pm1.g1 as x order by z limit 2";
    RelationalPlan plan = (RelationalPlan) helpPlan(sql, RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(), new String[] { "SELECT pm1.g1.e2 FROM pm1.g1" }, // $NON-NLS-1$
    TestOptimizer.SHOULD_SUCCEED);
    assertTrue(plan.getRootNode() instanceof LimitNode);
}
Also used : LimitNode(org.teiid.query.processor.relational.LimitNode) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 37 with DefaultCapabilitiesFinder

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

the class TestSortOptimization method testUnionWithAggregation.

@Test
public void testUnionWithAggregation() throws Exception {
    QueryMetadataInterface metadata = RealMetadataFactory.fromDDL("create foreign table items (item_id varchar)", "x", "y");
    String sql = "select FOO.SOURCE SOURCE, FOO.FOO_ID FOO_ID from (" + "(select 'X' SOURCE, ITEMS.ITEM_ID FOO_ID from ITEMS ITEMS group by ITEMS.ITEM_ID) " + "union all (select 'Y' SOURCE, ITEMS.ITEM_ID FOO_ID from ITEMS ITEMS) union all" + " (select 'Z' SOURCE, '123' FOO_ID) ) FOO order by FOO_ID desc limit 50";
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
    caps.setCapabilitySupport(Capability.QUERY_UNION, true);
    caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
    caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
    caps.setCapabilitySupport(Capability.QUERY_SET_LIMIT_OFFSET, true);
    helpPlan(sql, metadata, null, new DefaultCapabilitiesFinder(caps), new String[] { "SELECT 'X' AS c_0, g_1.item_id AS c_1 FROM y.items AS g_1 GROUP BY g_1.item_id UNION ALL SELECT 'Y' AS c_0, g_0.item_id AS c_1 FROM y.items AS g_0 ORDER BY c_1 DESC LIMIT 50" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 38 with DefaultCapabilitiesFinder

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

the class TestSortOptimization method testOrderedLimitOvewPreservedView.

@Test
public void testOrderedLimitOvewPreservedView() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table x (a string, b string, c integer, primary key (a, b)) options (updatable true); " + "create view SvcView (RowId integer PRIMARY KEY, code string, name string) as select c as x, a, b from x limit 2;", "x", "y");
    String sql = "select rowid, code, name from svcview order by rowid limit 1 ";
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, tm, null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT g_0.c, g_0.a, g_0.b FROM y.x AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.c, g_0.a, g_0.b FROM y.x AS g_0", Arrays.asList(1, "x", "a"), Arrays.asList(2, "z", "b"));
    List<?>[] expected = new List<?>[] { Arrays.asList(1, "x", "a") };
    helpProcess(plan, dataManager, expected);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) List(java.util.List) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 39 with DefaultCapabilitiesFinder

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

the class TestSortOptimization method testProjectionRaisingWithComplexOrdering.

@Test
public void testProjectionRaisingWithComplexOrdering() {
    // $NON-NLS-1$
    String sql = "select e1 || 1, e2 / 2 from pm1.g1 as x order by e1 || 1 limit 2";
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    bsc.setFunctionSupport(SourceSystemFunctions.CONCAT, true);
    bsc.setCapabilitySupport(Capability.ROW_LIMIT, true);
    CapabilitiesFinder finder = new DefaultCapabilitiesFinder(bsc);
    RelationalPlan plan = (RelationalPlan) helpPlan(sql, RealMetadataFactory.example1Cached(), null, finder, new String[] { "SELECT concat(g_0.e1, '1') AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0 LIMIT 2" }, // $NON-NLS-1$
    TestOptimizer.SHOULD_SUCCEED);
    assertTrue(plan.getRootNode() instanceof ProjectNode);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CapabilitiesFinder(org.teiid.query.optimizer.capabilities.CapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ProjectNode(org.teiid.query.processor.relational.ProjectNode) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 40 with DefaultCapabilitiesFinder

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

the class TestSortOptimization method testDistinctPushdown.

@Test
public void testDistinctPushdown() throws Exception {
    String sql = "select distinct e1, 1 from pm1.g1";
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_SELECT_DISTINCT, true);
    caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, false);
    caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
    helpPlan(sql, RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(caps), new String[] { "SELECT DISTINCT g_0.e1 FROM pm1.g1 AS g_0" }, // $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