Search in sources :

Example 1 with JoinNode

use of org.teiid.query.processor.relational.JoinNode 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 2 with JoinNode

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

the class TestJoinOptimization method testCopyCriteriaMultiway.

@Test
public void testCopyCriteriaMultiway() throws Exception {
    // $NON-NLS-1$
    String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla, bqt2.smalla, bqt1.smallb where bqt1.smalla.intnum = bqt2.smalla.intnum and cast(bqt1.smalla.stringkey as integer) = coalesce(bqt2.smalla.intkey, bqt1.smallb.intkey) and bqt2.smalla.intkey = 1";
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.exampleBQTCached(), new String[] { "SELECT g_0.IntKey FROM BQT1.SmallB AS g_0", "SELECT g_0.IntNum AS c_0, g_0.IntKey AS c_1 FROM BQT2.SmallA AS g_0 WHERE g_0.IntKey = 1 ORDER BY c_0", "SELECT g_0.IntNum AS c_0, g_0.StringKey AS c_1, g_0.IntKey AS c_2 FROM BQT1.SmallA AS g_0 ORDER BY c_0" });
    RelationalPlan relationalPlan = (RelationalPlan) plan;
    JoinNode joinNode = (JoinNode) relationalPlan.getRootNode().getChildren()[0];
    assertNotNull(joinNode.getJoinCriteria());
}
Also used : JoinNode(org.teiid.query.processor.relational.JoinNode) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 3 with JoinNode

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

the class TestDependentJoins method testLargeSetInDepAccessWithAccessPattern.

@Test
public void testLargeSetInDepAccessWithAccessPattern() {
    // $NON-NLS-1$
    String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e1=b.e1 AND a.e2 = b.e2";
    // Create expected results
    List[] expected = new List[] { Arrays.asList(new Object[] { "aa ", "aa ", // $NON-NLS-1$ //$NON-NLS-2$
    0 }), Arrays.asList(new Object[] { "bb   ", "bb   ", // $NON-NLS-1$ //$NON-NLS-2$
    1 }), Arrays.asList(new Object[] { "cc  ", "cc  ", // $NON-NLS-1$ //$NON-NLS-2$
    2 }) };
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
    depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
    depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
    depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm4", depcaps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1Cached();
    Command command = TestProcessor.helpParse(sql);
    ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
    // Verify a dependent join (not merge join) was used
    assertTrue(plan instanceof RelationalPlan);
    RelationalPlan relationalPlan = (RelationalPlan) plan;
    RelationalNode project = relationalPlan.getRootNode();
    RelationalNode join = project.getChildren()[0];
    // $NON-NLS-1$
    assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode);
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData2b(dataManager, fakeMetadata);
    // Run query
    TestProcessor.helpProcess(plan, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) RelationalNode(org.teiid.query.processor.relational.RelationalNode) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) JoinNode(org.teiid.query.processor.relational.JoinNode) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 4 with JoinNode

use of org.teiid.query.processor.relational.JoinNode 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 5 with JoinNode

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

the class TestProcessor method testComplexJoinExpressionsUsingDependentJoinWithAccessPattern.

/**
 * RLM Case 2077
 * @throws Exception
 */
@Test
public void testComplexJoinExpressionsUsingDependentJoinWithAccessPattern() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a, pm2.g1 b where rtrim(a.e1)=(b.e1 || b.e1)";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "bb   ", "b", new Integer(0) }) };
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
    // $NON-NLS-1$
    caps.setFunctionSupport("||", true);
    // $NON-NLS-1$
    caps.setFunctionSupport("rtrim", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm4", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm2", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.example1();
    RealMetadataFactory.setCardinality("pm4.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
    RealMetadataFactory.setCardinality("pm2.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata);
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleData2b(dataManager, metadata);
    Command command = helpParse(sql);
    CommandContext context = createCommandContext();
    context.setMetadata(metadata);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
    // Verify a dependent join (not merge join) was used
    assertTrue(plan instanceof RelationalPlan);
    RelationalPlan relationalPlan = (RelationalPlan) plan;
    RelationalNode project = relationalPlan.getRootNode();
    RelationalNode join = project.getChildren()[0];
    // $NON-NLS-1$
    assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode);
    // Run query
    helpProcess(plan, context, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) JoinNode(org.teiid.query.processor.relational.JoinNode) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) BigInteger(java.math.BigInteger) RelationalNode(org.teiid.query.processor.relational.RelationalNode) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Aggregations

JoinNode (org.teiid.query.processor.relational.JoinNode)9 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)8 Test (org.junit.Test)7 RelationalNode (org.teiid.query.processor.relational.RelationalNode)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)5 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)5 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)5 Command (org.teiid.query.sql.lang.Command)4 List (java.util.List)3 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)3 CommandContext (org.teiid.query.util.CommandContext)3 BigInteger (java.math.BigInteger)2 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)2 ArrayList (java.util.ArrayList)1 CapabilitiesFinder (org.teiid.query.optimizer.capabilities.CapabilitiesFinder)1 BlockingFakeRelationalNode (org.teiid.query.processor.relational.BlockingFakeRelationalNode)1 FakeRelationalNode (org.teiid.query.processor.relational.FakeRelationalNode)1 NestedTableJoinStrategy (org.teiid.query.processor.relational.NestedTableJoinStrategy)1