Search in sources :

Example 6 with JoinNode

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

the class TestProcessor method testComplexJoinExpressionsUsingDependentJoin.

/**
 * RLM Case 2077
 * @throws Exception
 */
@Test
public void testComplexJoinExpressionsUsingDependentJoin() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.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(1000));
    // $NON-NLS-1$
    caps.setFunctionSupport("||", true);
    // $NON-NLS-1$
    caps.setFunctionSupport("rtrim", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm2", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.example1();
    RealMetadataFactory.setCardinality("pm1.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)

Example 7 with JoinNode

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

the class TestDependentJoins method helpTestDepAccessCausingSortNodeInsert.

public void helpTestDepAccessCausingSortNodeInsert(boolean accessNodeHandlesAliases) {
    // $NON-NLS-1$
    String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e2=b.e2 AND a.e1 = b.e1 OPTION MAKEDEP a";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "aa ", "aa ", 0 }), // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "bb   ", "bb   ", 1 }), // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "cc  ", "cc  ", 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);
    if (accessNodeHandlesAliases) {
        depcaps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, 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);
    // Slightly modify metadata to set max set size to just a few rows - this
    // will allow us to test the dependent overflow case
    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)

Example 8 with JoinNode

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

the class TestTextTable method testTextTableJoin.

@Test
public void testTextTableJoin() throws Exception {
    String sql = "select z.* from (select x.* from (select * from pm1.g1 where e1 = 'c') y, texttable(e1 || '\n' || e2 || '\n' || e3 COLUMNS x string) x) as z, " + "(select x.* from (select * from pm1.g1 where e1 = 'c') y, texttable(e1 || '\n' || e2 || '\n' || e3 COLUMNS x string) x) as z1 where z.x = z1.x";
    List<?>[] expected = new List<?>[] { Arrays.asList("c"), Arrays.asList("1"), Arrays.asList("true") };
    FakeDataManager dataManager = new FakeDataManager();
    sampleData1(dataManager);
    RelationalPlan plan = (RelationalPlan) helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached());
    JoinNode join = (JoinNode) plan.getRootNode().getChildren()[0];
    assertTrue(!(join.getJoinStrategy() instanceof NestedTableJoinStrategy));
    helpProcess(plan, createCommandContext(), dataManager, expected);
}
Also used : NestedTableJoinStrategy(org.teiid.query.processor.relational.NestedTableJoinStrategy) JoinNode(org.teiid.query.processor.relational.JoinNode) ArrayList(java.util.ArrayList) List(java.util.List) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 9 with JoinNode

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

the class TestEnginePerformance method helpTestEquiJoin.

public void helpTestEquiJoin(int expectedRowCount, List<?>[] leftData, List<?>[] rightData, List<? extends Expression> elems, BufferManager bufferManager, JoinStrategy joinStrategy, JoinType joinType) throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    FakeRelationalNode dataNode1 = new FakeRelationalNode(1, leftData);
    dataNode1.setElements(elems);
    dataNode1.initialize(context, bufferManager, null);
    FakeRelationalNode dataNode2 = new FakeRelationalNode(2, rightData);
    dataNode2.setElements(elems);
    dataNode2.initialize(context, bufferManager, null);
    JoinNode join = new JoinNode(3);
    join.addChild(dataNode1);
    join.addChild(dataNode2);
    join.setJoinStrategy(joinStrategy.clone());
    join.setElements(elems);
    join.setJoinType(joinType);
    join.setJoinExpressions(elems.subList(0, 1), elems.subList(0, 1));
    join.initialize(context, bufferManager, null);
    process(join, expectedRowCount);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) JoinNode(org.teiid.query.processor.relational.JoinNode) BlockingFakeRelationalNode(org.teiid.query.processor.relational.BlockingFakeRelationalNode) FakeRelationalNode(org.teiid.query.processor.relational.FakeRelationalNode)

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