Search in sources :

Example 1 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.

the class TestPreparedPlanCache method helpPutPreparedPlans.

// ====Help methods====//
private void helpPutPreparedPlans(SessionAwareCache<PreparedPlan> cache, DQPWorkContext session, int start, int count) {
    for (int i = 0; i < count; i++) {
        Command dummy;
        try {
            dummy = QueryParser.getQueryParser().parseCommand(EXAMPLE_QUERY + (start + i));
        } catch (QueryParserException e) {
            throw new RuntimeException(e);
        }
        CacheID id = new CacheID(session, pi, dummy.toString());
        PreparedPlan pPlan = new PreparedPlan();
        cache.put(id, Determinism.SESSION_DETERMINISTIC, pPlan, null);
        pPlan.setCommand(dummy);
        pPlan.setPlan(new RelationalPlan(new ProjectNode(i)), new CommandContext());
        AnalysisRecord analysisRecord = new AnalysisRecord(true, false);
        pPlan.setAnalysisRecord(analysisRecord);
        ArrayList<Reference> refs = new ArrayList<Reference>();
        refs.add(new Reference(1));
        pPlan.setReferences(refs);
    }
}
Also used : QueryParserException(org.teiid.api.exception.query.QueryParserException) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Reference(org.teiid.query.sql.symbol.Reference) ArrayList(java.util.ArrayList) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Command(org.teiid.query.sql.lang.Command) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ProjectNode(org.teiid.query.processor.relational.ProjectNode)

Example 2 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord 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 3 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.

the class TestBatchedUpdatePlanner method helpPlanCommand.

private BatchedUpdatePlan helpPlanCommand(Command command, QueryMetadataInterface md, CapabilitiesFinder capFinder, boolean shouldSucceed) throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
    // plan
    ProcessorPlan plan = null;
    AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
    if (shouldSucceed) {
        try {
            // do planning
            plan = QueryOptimizer.optimizePlan(command, md, null, capFinder, analysisRecord, null);
        } finally {
            if (DEBUG) {
                System.out.println(analysisRecord.getDebugLog());
            }
        }
        return (BatchedUpdatePlan) plan;
    }
    Exception exception = null;
    try {
        // do planning
        QueryOptimizer.optimizePlan(command, md, null, capFinder, analysisRecord, null);
    } catch (QueryPlannerException e) {
        exception = e;
    } catch (TeiidComponentException e) {
        exception = e;
    } finally {
        if (DEBUG) {
            System.out.println(analysisRecord.getDebugLog());
        }
    }
    // $NON-NLS-1$
    assertNotNull("Expected exception but did not get one.", exception);
    return null;
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) TeiidComponentException(org.teiid.core.TeiidComponentException) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException) BatchedUpdatePlan(org.teiid.query.processor.BatchedUpdatePlan)

Example 4 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.

the class TestAccessPatterns method testMultiAccessPatternWithCriteria.

/*
     * Criteria was preventing rule choose dependent from creating the appropriate dependent join
     */
@Test
public void testMultiAccessPatternWithCriteria() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT pm1.g1.* FROM pm4.g1, pm5.g1, pm1.g1 where pm4.g1.e1 = pm1.g1.e1 and pm5.g1.e1 = pm1.g1.e1 and pm5.g1.e2 like '%x' ";
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    AnalysisRecord record = new AnalysisRecord(true, true);
    TestOptimizer.helpPlanCommand(TestOptimizer.helpGetCommand(sql, metadata, null), metadata, TestOptimizer.getGenericFinder(false), record, new String[] { // $NON-NLS-1$
    "SELECT g_0.e2, g_0.e1 FROM pm5.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", // $NON-NLS-1$
    "SELECT g_0.e1, g_0.e2, g_0.e3, g_0.e4 FROM pm1.g1 AS g_0", "SELECT g_0.e1 FROM pm4.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    assertTrue(record.getAnnotations().toString().contains("access pattern not satisfied by join"));
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 5 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.

the class TestProcessor method helpGetPlan.

public static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context) throws TeiidException {
    // $NON-NLS-1$
    if (DEBUG)
        System.out.println("\n####################################\n" + command);
    AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
    if (!(metadata instanceof TempMetadataAdapter)) {
        metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());
    }
    context.setMetadata(metadata);
    try {
        QueryResolver.resolveCommand(command, metadata);
        ValidatorReport repo = Validator.validate(command, metadata);
        Collection failures = new ArrayList();
        repo.collectInvalidObjects(failures);
        if (failures.size() > 0) {
            // $NON-NLS-1$
            throw new QueryValidatorException("Exception during validation:" + repo);
        }
        command = QueryRewriter.rewrite(command, metadata, context);
        ProcessorPlan process = QueryOptimizer.optimizePlan(command, metadata, null, capFinder, analysisRecord, context);
        // $NON-NLS-1$
        if (DEBUG)
            System.out.println("\n" + process);
        // per defect 10022, clone this plan before processing, just to make sure
        // a cloned plan with correlated subquery references (or any cloned plan) can be processed
        process = process.clone();
        // $NON-NLS-1$
        assertNotNull("Output elements of process plan are null", process.getOutputElements());
        return process;
    } finally {
        if (DEBUG) {
            System.out.println(analysisRecord.getDebugLog());
        }
    }
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Aggregations

AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)31 Command (org.teiid.query.sql.lang.Command)21 Test (org.junit.Test)19 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)16 Annotation (org.teiid.client.plan.Annotation)9 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)9 CommandContext (org.teiid.query.util.CommandContext)8 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)7 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)4 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)4 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)4 ValidatorReport (org.teiid.query.validator.ValidatorReport)4 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)3 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)3 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)3 GlobalTableStoreImpl (org.teiid.query.tempdata.GlobalTableStoreImpl)3 TeiidComponentException (org.teiid.core.TeiidComponentException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2