Search in sources :

Example 31 with RelationalPlan

use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.

the class TestSortOptimization method testProjectionRaisingWithComplexOrdering1.

@Test
public void testProjectionRaisingWithComplexOrdering1() {
    // $NON-NLS-1$
    String sql = "select e1 || 1 as a, e2 / 2 from pm1.g1 as x order by a, e2 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, c_1 LIMIT 2" }, // $NON-NLS-1$
    TestOptimizer.SHOULD_SUCCEED);
    assertTrue(plan.getRootNode() instanceof ProjectNode);
    HardcodedDataManager hdm = new HardcodedDataManager();
    hdm.addData("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, c_1 LIMIT 2", Arrays.asList("c1", 2), Arrays.asList("d1", 3));
    TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList("c1", 1), Arrays.asList("d1", 1) });
}
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) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) 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 32 with RelationalPlan

use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.

the class TestCalculateCostUtil method helpTestQuery.

private void helpTestQuery(float cost, String query, String[] expected) throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$ //$NON-NLS-2$
    RelationalPlan plan = (RelationalPlan) TestOptimizer.helpPlan(query, TestVirtualDepJoin.exampleVirtualDepJoin(), expected, ComparisonMode.EXACT_COMMAND_STRING);
    assertEquals(cost, plan.getRootNode().getEstimateNodeCardinality());
}
Also used : RelationalPlan(org.teiid.query.processor.relational.RelationalPlan)

Example 33 with RelationalPlan

use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.

the class TestJoinOptimization method testOuterJoinRemoval.

@Test
public void testOuterJoinRemoval() throws Exception {
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, false);
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    "SELECT * from pm1.g1 inner join (pm1.g2 left outer join pm1.g3 on pm1.g2.e1=pm1.g3.e1) on pm1.g1.e1=pm1.g3.e1", RealMetadataFactory.example1Cached(), new String[] { "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g2 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g3 AS g_0 ORDER BY c_0" }, new DefaultCapabilitiesFinder(caps), // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    RelationalNode node = ((RelationalPlan) plan).getRootNode().getChildren()[0];
    assertTrue(node instanceof JoinNode);
    node = node.getChildren()[0];
    assertTrue(node instanceof JoinNode);
    assertEquals(JoinType.JOIN_INNER, ((JoinNode) node).getJoinType());
}
Also used : RelationalNode(org.teiid.query.processor.relational.RelationalNode) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) JoinNode(org.teiid.query.processor.relational.JoinNode) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 34 with RelationalPlan

use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.

the class TestMaterialization method testDefaultMaterializationWithPK.

@Test
public void testDefaultMaterializationWithPK() throws Exception {
    // $NON-NLS-1$
    String userSql = "SELECT * from vgroup3 where x = 'foo'";
    TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView();
    AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
    Command command = helpGetCommand(userSql, metadata, null);
    CommandContext cc = new CommandContext();
    GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata);
    cc.setGlobalTableStore(gts);
    RelationalPlan plan = (RelationalPlan) TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc);
    assertEquals(1f, plan.getRootNode().getEstimateNodeCardinality());
    TestOptimizer.checkAtomicQueries(new String[] { "SELECT #MAT_MATVIEW.VGROUP3.x, #MAT_MATVIEW.VGROUP3.y FROM #MAT_MATVIEW.VGROUP3 WHERE #MAT_MATVIEW.VGROUP3.x = 'foo'" }, plan);
    Collection<Annotation> annotations = analysis.getAnnotations();
    // $NON-NLS-1$
    assertNotNull("Expected annotations but got none", annotations);
    // $NON-NLS-1$
    assertEquals("Expected one annotation", 1, annotations.size());
    // $NON-NLS-1$
    assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Annotation(org.teiid.client.plan.Annotation) Test(org.junit.Test)

Example 35 with RelationalPlan

use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.

the class TestCalculateCostUtil method testLimitWithUnknownChildCardinality.

@Test
public void testLimitWithUnknownChildCardinality() throws Exception {
    // $NON-NLS-1$
    String query = "select e1 from pm1.g1 limit 2";
    // $NON-NLS-1$
    RelationalPlan plan = (RelationalPlan) TestOptimizer.helpPlan(query, RealMetadataFactory.example1Cached(), new String[] { "SELECT e1 FROM pm1.g1" });
    assertEquals(new Float(2), plan.getRootNode().getEstimateNodeCardinality());
}
Also used : RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Aggregations

RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)40 Test (org.junit.Test)25 RelationalNode (org.teiid.query.processor.relational.RelationalNode)12 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)11 Command (org.teiid.query.sql.lang.Command)10 List (java.util.List)9 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)9 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)8 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)8 AccessNode (org.teiid.query.processor.relational.AccessNode)8 JoinNode (org.teiid.query.processor.relational.JoinNode)8 ArrayList (java.util.ArrayList)7 ProjectNode (org.teiid.query.processor.relational.ProjectNode)7 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)5 Annotation (org.teiid.client.plan.Annotation)4 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)4 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)4 LanguageObject (org.teiid.query.sql.LanguageObject)4 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)3 CapabilitiesFinder (org.teiid.query.optimizer.capabilities.CapabilitiesFinder)3