Search in sources :

Example 16 with AnalysisRecord

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

the class TestMaterialization method testManagedMaterializedTransformationJoin.

@Test
public void testManagedMaterializedTransformationJoin() throws Exception {
    // make sure view removal is not inhibited
    // $NON-NLS-1$
    String userSql = "SELECT MatTable1.*,ManagedMatView.* FROM ManagedMatView left outer join MatTable1 on ManagedMatView.e1 = MatTable1.e1";
    QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
    AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
    Command command = helpGetCommand(userSql, metadata, null);
    TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] { // $NON-NLS-1$
    "SELECT g_1.e1, g_0.e1 FROM MatTable.MatTable AS g_0 LEFT OUTER JOIN MatTable.MatTable1 AS g_1 ON g_0.e1 = g_1.e1 WHERE mvstatus('MatView', 'ManagedMatView') = 1" }, ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 17 with AnalysisRecord

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

the class XMLQuery method compileXqueryExpression.

// TODO: display the analysis record info
public void compileXqueryExpression() throws QueryResolverException {
    this.xqueryExpression = new SaxonXQueryExpression(xquery, namespaces, passing, null);
    this.xqueryExpression.useDocumentProjection(null, new AnalysisRecord(false, false));
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) SaxonXQueryExpression(org.teiid.query.xquery.saxon.SaxonXQueryExpression)

Example 18 with AnalysisRecord

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

the class QueryProcessorFactoryImpl method getPreparedPlan.

@Override
public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException {
    if (recursionGroup != null) {
        commandContext.pushCall(recursionGroup);
    }
    PreparedPlan pp = commandContext.getPlan(query);
    if (pp == null) {
        ParseInfo parseInfo = new ParseInfo();
        Command newCommand = QueryParser.getQueryParser().parseCommand(query, parseInfo);
        QueryResolver.resolveCommand(newCommand, metadata);
        List<Reference> references = ReferenceCollectorVisitor.getReferences(newCommand);
        AbstractValidationVisitor visitor = new ValidationVisitor();
        Request.validateWithVisitor(visitor, metadata, newCommand);
        newCommand = QueryRewriter.rewrite(newCommand, metadata, commandContext);
        AnalysisRecord record = new AnalysisRecord(false, false);
        ProcessorPlan plan = QueryOptimizer.optimizePlan(newCommand, metadata, idGenerator, finder, record, commandContext);
        pp = new PreparedPlan();
        pp.setPlan(plan, commandContext);
        pp.setReferences(references);
        pp.setAnalysisRecord(record);
        pp.setCommand(newCommand);
        commandContext.putPlan(query, pp, commandContext.getDeterminismLevel());
    }
    return pp;
}
Also used : AbstractValidationVisitor(org.teiid.query.validator.AbstractValidationVisitor) ValidationVisitor(org.teiid.query.validator.ValidationVisitor) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) Command(org.teiid.query.sql.lang.Command) Reference(org.teiid.query.sql.symbol.Reference) ParseInfo(org.teiid.query.parser.ParseInfo) AbstractValidationVisitor(org.teiid.query.validator.AbstractValidationVisitor) ProcessorPlan(org.teiid.query.processor.ProcessorPlan)

Example 19 with AnalysisRecord

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

the class QueryOptimizer method optimizePlan.

public static ProcessorPlan optimizePlan(Command command, QueryMetadataInterface metadata, IDGenerator idGenerator, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context) throws QueryMetadataException, TeiidComponentException, QueryPlannerException {
    if (analysisRecord == null) {
        analysisRecord = new AnalysisRecord(false, false);
    }
    if (context == null) {
        context = new CommandContext();
    }
    if (!(capFinder instanceof TempCapabilitiesFinder)) {
        capFinder = new TempCapabilitiesFinder(capFinder);
    }
    boolean debug = analysisRecord.recordDebug();
    if (!(metadata instanceof TempMetadataAdapter)) {
        metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());
    }
    if (context.getMetadata() == null) {
        context.setMetadata(metadata);
    }
    // Create an ID generator that can be used for all plans to generate unique data node IDs
    if (idGenerator == null) {
        idGenerator = new IDGenerator();
    }
    if (debug) {
        // $NON-NLS-1$
        analysisRecord.println("\n----------------------------------------------------------------------------");
        // $NON-NLS-1$
        analysisRecord.println("OPTIMIZE: \n" + command);
    }
    if (command instanceof Insert) {
        Insert insert = (Insert) command;
        if (insert.isUpsert()) {
            // if not supported or there are trigger actions, then rewrite as a procedure
            // we do this here since we're changing the command type.
            // TODO: we could push this back into the rewrite, but it will need to be capabilities aware
            GroupSymbol group = insert.getGroup();
            Object modelId = metadata.getModelID(group.getMetadataID());
            boolean supportsUpsert = CapabilitiesUtil.supports(Capability.UPSERT, modelId, metadata, capFinder);
            if (!supportsUpsert) {
                try {
                    command = QueryRewriter.rewriteAsUpsertProcedure(insert, metadata, context);
                } catch (TeiidProcessingException e) {
                    throw new QueryPlannerException(e);
                }
                if (debug) {
                    // $NON-NLS-1$
                    analysisRecord.println("\n----------------------------------------------------------------------------");
                    // $NON-NLS-1$
                    analysisRecord.println("OPTIMIZE UPSERT PROCEDURE: \n" + command);
                }
            }
        }
    }
    ProcessorPlan result = null;
    switch(command.getType()) {
        case Command.TYPE_UPDATE_PROCEDURE:
            CreateProcedureCommand cupc = (CreateProcedureCommand) command;
            if (cupc.getUpdateType() != Command.TYPE_UNKNOWN || cupc.getVirtualGroup() == null) {
                // row update procedure or anon block
                result = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, context);
            } else {
                Object pid = cupc.getVirtualGroup().getMetadataID();
                if (pid instanceof TempMetadataID) {
                    TempMetadataID tid = (TempMetadataID) pid;
                    if (tid.getOriginalMetadataID() != null) {
                        pid = tid.getOriginalMetadataID();
                    }
                }
                String fullName = metadata.getFullName(pid);
                // $NON-NLS-1$
                fullName = "procedure cache:" + fullName;
                PreparedPlan pp = context.getPlan(fullName);
                if (pp == null) {
                    Determinism determinismLevel = context.resetDeterminismLevel();
                    try {
                        CommandContext clone = context.clone();
                        ProcessorPlan plan = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, clone);
                        // note that this is not a full prepared plan.  It is not usable by user queries.
                        if (pid instanceof Procedure) {
                            clone.accessedPlanningObject(pid);
                        }
                        pp = new PreparedPlan();
                        pp.setPlan(plan, clone);
                        context.putPlan(fullName, pp, context.getDeterminismLevel());
                    } finally {
                        context.setDeterminismLevel(determinismLevel);
                    }
                }
                result = pp.getPlan().clone();
                for (Object id : pp.getAccessInfo().getObjectsAccessed()) {
                    context.accessedPlanningObject(id);
                }
            }
            break;
        case Command.TYPE_BATCHED_UPDATE:
            result = BATCHED_UPDATE_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
            break;
        case Command.TYPE_ALTER_PROC:
        case Command.TYPE_ALTER_TRIGGER:
        case Command.TYPE_ALTER_VIEW:
            result = DDL_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
            break;
        case Command.TYPE_SOURCE_EVENT:
            result = SOURCE_EVENT_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
            break;
        default:
            try {
                RelationalPlanner planner = new RelationalPlanner();
                planner.initialize(command, idGenerator, metadata, capFinder, analysisRecord, context);
                result = planner.optimize(command);
            } catch (QueryResolverException e) {
                throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30245, e);
            }
    }
    if (debug) {
        // $NON-NLS-1$
        analysisRecord.println("\n----------------------------------------------------------------------------");
        // $NON-NLS-1$
        analysisRecord.println("OPTIMIZATION COMPLETE:");
        // $NON-NLS-1$
        analysisRecord.println("PROCESSOR PLAN:\n" + result);
        // $NON-NLS-1$
        analysisRecord.println("============================================================================");
    }
    return result;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) Determinism(org.teiid.metadata.FunctionMethod.Determinism) CommandContext(org.teiid.query.util.CommandContext) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) TempMetadataID(org.teiid.query.metadata.TempMetadataID) TempCapabilitiesFinder(org.teiid.query.metadata.TempCapabilitiesFinder) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Insert(org.teiid.query.sql.lang.Insert) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) RelationalPlanner(org.teiid.query.optimizer.relational.RelationalPlanner) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) Procedure(org.teiid.metadata.Procedure) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) IDGenerator(org.teiid.core.id.IDGenerator) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore)

Example 20 with AnalysisRecord

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

the class TestMultiSourcePlanToProcessConverter method helpTestMultiSourcePlan.

public ProcessorPlan helpTestMultiSourcePlan(QueryMetadataInterface metadata, String userSql, String multiModel, int sourceCount, ProcessorDataManager dataMgr, List<?>[] expectedResults, VDBMetaData vdb, List<?> params, Options options, SourceCapabilities bsc) throws Exception {
    Map<String, String> multiSourceModels = MultiSourceMetadataWrapper.getMultiSourceModels(vdb);
    for (String model : multiSourceModels.keySet()) {
        char sourceID = 'a';
        // by default every model has one binding associated, but for multi-source there were none assigned.
        ModelMetaData m = vdb.getModel(model);
        int x = m.getSourceNames().size();
        for (int i = x; i < sourceCount; i++, sourceID++) {
            // $NON-NLS-1$ //$NON-NLS-2$
            m.addSourceMapping("" + sourceID, "translator", null);
        }
    }
    QueryMetadataInterface wrapper = new MultiSourceMetadataWrapper(metadata, multiSourceModels);
    wrapper = new TempMetadataAdapter(wrapper, new TempMetadataStore());
    DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(wrapper, vdb);
    AnalysisRecord analysis = new AnalysisRecord(DEBUG, DEBUG);
    Command command = TestResolver.helpResolve(userSql, wrapper);
    ValidatorReport report = Validator.validate(command, metadata);
    if (report.hasItems()) {
        fail(report.toString());
    }
    // Plan
    command = QueryRewriter.rewrite(command, wrapper, null);
    DefaultCapabilitiesFinder fakeFinder = new DefaultCapabilitiesFinder(bsc);
    CapabilitiesFinder finder = new TempCapabilitiesFinder(fakeFinder);
    IDGenerator idGenerator = new IDGenerator();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    CommandContext context = new CommandContext("test", "user", null, vdb.getName(), vdb.getVersion(), false);
    context.setDQPWorkContext(workContext);
    context.setOptions(options);
    ProcessorPlan plan = QueryOptimizer.optimizePlan(command, wrapper, idGenerator, finder, analysis, context);
    if (DEBUG) {
        System.out.println(analysis.getDebugLog());
        // $NON-NLS-1$
        System.out.println("\nMultiSource Plan:");
        System.out.println(plan);
    }
    if (params != null) {
        TestProcessor.setParameterValues(params, command, context);
    }
    TestProcessor.helpProcess(plan, context, dataMgr, expectedResults);
    return plan;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) TempCapabilitiesFinder(org.teiid.query.metadata.TempCapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) TempCapabilitiesFinder(org.teiid.query.metadata.TempCapabilitiesFinder) CapabilitiesFinder(org.teiid.query.optimizer.capabilities.CapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) IDGenerator(org.teiid.core.id.IDGenerator) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore)

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