Search in sources :

Example 51 with ProcessorPlan

use of org.teiid.query.processor.ProcessorPlan in project teiid by teiid.

the class TestOptimizer method getPlan.

public static ProcessorPlan getPlan(Command command, QueryMetadataInterface md, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, boolean shouldSucceed, CommandContext cc) {
    ProcessorPlan plan = null;
    if (analysisRecord == null) {
        analysisRecord = new AnalysisRecord(false, DEBUG);
    }
    Exception exception = null;
    try {
        // do planning
        plan = QueryOptimizer.optimizePlan(command, md, null, capFinder, analysisRecord, cc);
    } catch (QueryPlannerException e) {
        exception = e;
    } catch (TeiidComponentException e) {
        exception = e;
    } catch (Throwable e) {
        throw new TeiidRuntimeException(e);
    } finally {
        if (DEBUG) {
            System.out.println(analysisRecord.getDebugLog());
        }
    }
    if (!shouldSucceed) {
        // $NON-NLS-1$
        assertNotNull("Expected exception but did not get one.", exception);
        return null;
    }
    if (plan == null) {
        throw new TeiidRuntimeException(exception);
    }
    // $NON-NLS-1$
    assertNotNull("Output elements are null", plan.getOutputElements());
    // $NON-NLS-1$
    if (DEBUG)
        System.out.println("\n" + plan);
    return plan;
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidException(org.teiid.core.TeiidException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException)

Example 52 with ProcessorPlan

use of org.teiid.query.processor.ProcessorPlan in project teiid by teiid.

the class TestOptimizer method testLookupFunction.

/**
 * defect 11630 - note that the lookup function is not pushed down, it will actually be evaluated before being sent to the connector
 */
@Test
public void testLookupFunction() {
    ProcessorPlan plan = helpPlan(// $NON-NLS-1$
    "SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1','e1', 'e2', 1) IS NULL", // $NON-NLS-1$
    RealMetadataFactory.example1Cached(), // $NON-NLS-1$
    new String[] { "SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1', 'e1', 'e2', 1) IS NULL" });
    checkNodeTypes(plan, FULL_PUSHDOWN);
}
Also used : ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 53 with ProcessorPlan

use of org.teiid.query.processor.ProcessorPlan in project teiid by teiid.

the class TestOptimizer method testUseMergeJoin7.

/**
 * one side of join supports order by, the other doesn't
 */
@Test
public void testUseMergeJoin7() throws Exception {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g2 WHERE pm1.g1.e1 = pm2.g2.e1";
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm2", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.example1();
    RealMetadataFactory.setCardinality("pm1.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500, metadata);
    RealMetadataFactory.setCardinality("pm2.g2", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
    ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 ORDER BY pm1.g1.e1", "SELECT pm2.g2.e1 FROM pm2.g2" }, // $NON-NLS-1$ //$NON-NLS-2$
    SHOULD_SUCCEED);
    checkNodeTypes(plan, new int[] { // Access
    2, // DependentAccess
    0, // 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 54 with ProcessorPlan

use of org.teiid.query.processor.ProcessorPlan in project teiid by teiid.

the class TestOptimizer method testPushGroupBy3.

@Test
public void testPushGroupBy3() {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    ProcessorPlan plan = helpPlan(// $NON-NLS-1$
    "SELECT e1, e2 as x FROM pm1.g1 GROUP BY e1, e2", RealMetadataFactory.example1Cached(), null, capFinder, // $NON-NLS-1$
    new String[] { "SELECT e1, e2 FROM pm1.g1" }, SHOULD_SUCCEED);
    checkNodeTypes(plan, new int[] { // Access
    1, // DependentAccess
    0, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    1, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    0, // 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) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 55 with ProcessorPlan

use of org.teiid.query.processor.ProcessorPlan in project teiid by teiid.

the class TestOptimizer method testExceptPushdown.

@Test
public void testExceptPushdown() throws Exception {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_EXCEPT, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // $NON-NLS-1$
    String sql = "select e1 from pm1.g1 except select e1 from pm1.g2";
    ProcessorPlan plan = helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder, new String[] { "SELECT g_1.e1 AS c_0 FROM pm1.g1 AS g_1 EXCEPT SELECT g_0.e1 AS c_0 FROM pm1.g2 AS g_0" }, // $NON-NLS-1$
    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    checkNodeTypes(plan, FULL_PUSHDOWN);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Aggregations

ProcessorPlan (org.teiid.query.processor.ProcessorPlan)814 Test (org.junit.Test)764 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)357 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)290 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)177 List (java.util.List)112 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)108 ArrayList (java.util.ArrayList)99 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)97 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)88 FakeDataManager (org.teiid.query.processor.FakeDataManager)86 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)33 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)32 CommandContext (org.teiid.query.util.CommandContext)26 Ignore (org.junit.Ignore)21 Command (org.teiid.query.sql.lang.Command)19 TeiidProcessingException (org.teiid.core.TeiidProcessingException)9 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)9 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)8 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)8