Search in sources :

Example 36 with RelationalPlan

use of org.teiid.query.processor.relational.RelationalPlan 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)

Example 37 with RelationalPlan

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

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

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

the class TestTextTable method testTextTableJoinPrefetch.

@Test
public void testTextTableJoinPrefetch() 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";
    List<?>[] expected = new List<?>[] { Arrays.asList("c"), Arrays.asList("1"), Arrays.asList("true") };
    FakeDataManager dataManager = new FakeDataManager();
    dataManager.setBlockOnce();
    sampleData1(dataManager);
    RelationalPlan plan = (RelationalPlan) helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached());
    helpProcess(plan, createCommandContext(), dataManager, expected);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 40 with RelationalPlan

use of org.teiid.query.processor.relational.RelationalPlan 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)

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