Search in sources :

Example 61 with QueryMetadataInterface

use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.

the class TestDependentJoins method testNestedLeftOuterJoin.

@Test
public void testNestedLeftOuterJoin() throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    String sql = "select pm1.g1.e2, 'a', trim(pm1.g3.e1) from (pm1.g1 left outer join pm1.g2 on pm1.g1.e2 = pm1.g2.e2) left outer join pm1.g3 on pm1.g3.e3 = pm1.g2.e3 and pm1.g3.e4 = pm1.g1.e4";
    QueryMetadataInterface metadata = RealMetadataFactory.example1();
    // $NON-NLS-1$
    RealMetadataFactory.setCardinality("pm1.g2", 6, metadata);
    // $NON-NLS-1$
    RealMetadataFactory.setCardinality("pm1.g1", 0, metadata);
    // $NON-NLS-1$
    RealMetadataFactory.setCardinality("pm1.g3", 0, metadata);
    CapabilitiesFinder finder = TestOptimizer.getGenericFinder(false);
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, new String[] { "SELECT g_0.e3, g_0.e4, g_0.e1 FROM pm1.g3 AS g_0", "SELECT g_0.e2, g_0.e4 FROM pm1.g1 AS g_0", "SELECT g_0.e2, g_0.e3 FROM pm1.g2 AS g_0 WHERE g_0.e2 IN (<dependent values>)" }, finder, ComparisonMode.EXACT_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, new int[] { // Access
    2, // DependentAccess
    1, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    0, // Join
    0, // MergeJoin
    2, // Null
    0, // PlanExecution
    0, // Project
    1, // Select
    0, // Sort
    0, // UnionAll
    0 });
    RelationalPlan rPlan = (RelationalPlan) plan;
    RelationalNode node = rPlan.getRootNode().getChildren()[0];
    assertTrue(node instanceof JoinNode);
    node = node.getChildren()[0];
    assertTrue(node instanceof JoinNode);
    assertEquals(JoinType.JOIN_LEFT_OUTER, ((JoinNode) node).getJoinType());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CapabilitiesFinder(org.teiid.query.optimizer.capabilities.CapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) RelationalNode(org.teiid.query.processor.relational.RelationalNode) JoinNode(org.teiid.query.processor.relational.JoinNode) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 62 with QueryMetadataInterface

use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.

the class TestDependentJoins method testMakedepWithAggregatePushdown.

/**
 * Makes sure that hints are considered after rule push aggregates
 * @throws Exception
 */
@Test
public void testMakedepWithAggregatePushdown() throws Exception {
    // $NON-NLS-1$
    String sql = "select count(x.e2), pm2.g2.e1 from pm1.g1 x makedep, pm2.g2 where x.e4 = pm2.g2.e4 group by pm2.g2.e1";
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, null, new DefaultCapabilitiesFinder(TestOptimizer.getTypicalCapabilities()), new String[] { "SELECT g_0.e4, g_0.e2 FROM pm1.g1 AS g_0 WHERE g_0.e4 IN (<dependent values>)", "SELECT g_0.e4 AS c_0, g_0.e1 AS c_1 FROM pm2.g2 AS g_0 ORDER BY c_0" }, // $NON-NLS-1$ //$NON-NLS-2$
    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, new int[] { // Access
    1, // DependentAccess
    1, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    2, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    1, // Null
    0, // PlanExecution
    0, // Project
    1, // Select
    0, // Sort
    0, // UnionAll
    0 });
}
Also used : QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 63 with QueryMetadataInterface

use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.

the class TestDependentJoins method testPlanningOverJoin.

@Test
public void testPlanningOverJoin() throws Exception {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT pm1.g1.e1 FROM pm1.g1, (select pm2.g2.e1, pm2.g3.e2 from pm2.g2 left outer join pm2.g3 on pm2.g2.e1 = pm2.g3.e1) as x where pm1.g1.e1 = x.e1";
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm2", TestOptimizer.getTypicalCapabilities());
    QueryMetadataInterface metadata = RealMetadataFactory.example1();
    RealMetadataFactory.setCardinality("pm1.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY, metadata);
    RealMetadataFactory.setCardinality("pm2.g2", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1, metadata);
    RealMetadataFactory.setCardinality("pm2.g3", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1, metadata);
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, null, capFinder, new String[] { "SELECT g_0.e1 AS c_0 FROM pm2.g2 AS g_0 LEFT OUTER JOIN pm2.g3 AS g_1 ON g_0.e1 = g_1.e1 WHERE g_0.e1 IN (<dependent values>) ORDER BY c_0", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$ //$NON-NLS-2$
    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, new int[] { // Access
    1, // DependentAccess
    1, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    0, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    1, // Null
    0, // PlanExecution
    0, // Project
    1, // Select
    0, // Sort
    0, // UnionAll
    0 });
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 64 with QueryMetadataInterface

use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.

the class TestDependentJoins method testMultiMergeJoin3.

/**
 * should have one dependent joins
 */
@Test
public void testMultiMergeJoin3() throws Exception {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT pm1.g2.e1 FROM pm1.g3, pm1.g2, pm1.g1 WHERE pm1.g2.e1 = pm1.g3.e1 AND pm1.g1.e1 = pm1.g2.e1";
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
    caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.example1();
    RealMetadataFactory.setCardinality("pm1.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1, metadata);
    RealMetadataFactory.setCardinality("pm1.g2", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata);
    RealMetadataFactory.setCardinality("pm1.g3", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, null, capFinder, new String[] { "SELECT g_0.e1 FROM pm1.g3 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, new int[] { // Access
    2, // DependentAccess
    1, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    0, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    2, // Null
    0, // PlanExecution
    0, // Project
    1, // Select
    0, // Sort
    0, // UnionAll
    0 });
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 65 with QueryMetadataInterface

use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.

the class TestDependentJoins method testMergeJoinVirtualGroups.

@Test
public void testMergeJoinVirtualGroups() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT vm1.g1.e1 FROM vm1.g1, vm1.g2a WHERE vm1.g1.e1 = vm1.g2a.e1";
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
    caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
    caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
    caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.example1();
    RealMetadataFactory.setCardinality("pm1.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata);
    RealMetadataFactory.setCardinality("pm1.g2", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, null, capFinder, new String[] { "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0 FROM pm1.g2 AS g_0 WHERE g_0.e1 IN (<dependent values>) ORDER BY c_0" }, // $NON-NLS-1$ //$NON-NLS-2$
    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, new int[] { // Access
    1, // DependentAccess
    1, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    0, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    1, // Null
    0, // PlanExecution
    0, // Project
    1, // Select
    0, // Sort
    0, // UnionAll
    0 });
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Aggregations

QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)507 Test (org.junit.Test)464 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)210 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)189 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)177 List (java.util.List)126 Command (org.teiid.query.sql.lang.Command)90 ArrayList (java.util.ArrayList)72 FakeDataManager (org.teiid.query.processor.FakeDataManager)48 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)43 BigInteger (java.math.BigInteger)41 CommandContext (org.teiid.query.util.CommandContext)37 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)29 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)16 MetadataStore (org.teiid.metadata.MetadataStore)12 Schema (org.teiid.metadata.Schema)11 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)11 TeiidException (org.teiid.core.TeiidException)10 TeiidProcessingException (org.teiid.core.TeiidProcessingException)10 CapabilitiesFinder (org.teiid.query.optimizer.capabilities.CapabilitiesFinder)10