Search in sources :

Example 16 with TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter in project teiid by teiid.

the class UpdateProcedureResolver method resolveBlock.

public void resolveBlock(CreateProcedureCommand command, Block block, GroupContext originalExternalGroups, TempMetadataAdapter original) throws QueryResolverException, QueryMetadataException, TeiidComponentException {
    // $NON-NLS-1$
    LogManager.logTrace(org.teiid.logging.LogConstants.CTX_QUERY_RESOLVER, new Object[] { "Resolving block", block });
    // create a new variable and metadata context for this block so that discovered metadata is not visible else where
    TempMetadataStore store = original.getMetadataStore().clone();
    TempMetadataAdapter metadata = new TempMetadataAdapter(original.getMetadata(), store);
    GroupContext externalGroups = new GroupContext(originalExternalGroups, null);
    // create a new variables group for this block
    GroupSymbol variables = ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.VARIABLES, store, externalGroups, new LinkedList<Expression>());
    for (Statement statement : block.getStatements()) {
        resolveStatement(command, statement, externalGroups, variables, metadata);
    }
    if (block.getExceptionGroup() != null) {
        // create a new variable and metadata context for this block so that discovered metadata is not visible else where
        store = original.getMetadataStore().clone();
        metadata = new TempMetadataAdapter(original.getMetadata(), store);
        externalGroups = new GroupContext(originalExternalGroups, null);
        // create a new variables group for this block
        variables = ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.VARIABLES, store, externalGroups, new LinkedList<Expression>());
        isValidGroup(metadata, block.getExceptionGroup());
        if (block.getExceptionStatements() != null) {
            ProcedureContainerResolver.addScalarGroup(block.getExceptionGroup(), store, externalGroups, exceptionGroup, false);
            for (Statement statement : block.getExceptionStatements()) {
                resolveStatement(command, statement, externalGroups, variables, metadata);
            }
        }
    }
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) Expression(org.teiid.query.sql.symbol.Expression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) GroupContext(org.teiid.query.sql.lang.GroupContext) LinkedList(java.util.LinkedList)

Example 17 with TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter in project teiid by teiid.

the class Request method initMetadata.

/**
 * if the metadata has not been supplied via setMetadata, this method will create the appropriate state
 *
 * @throws TeiidComponentException
 */
protected void initMetadata() throws TeiidComponentException {
    if (this.metadata != null) {
        return;
    }
    // Prepare dependencies for running the optimizer
    this.capabilitiesFinder = new CachedFinder(this.connectorManagerRepo, workContext.getVDB());
    if (this.bufferManager.getOptions() != null) {
        this.capabilitiesFinder = new TempCapabilitiesFinder(this.capabilitiesFinder, this.bufferManager.getOptions().getDefaultNullOrder());
    } else {
        this.capabilitiesFinder = new TempCapabilitiesFinder(this.capabilitiesFinder);
    }
    VDBMetaData vdbMetadata = workContext.getVDB();
    metadata = vdbMetadata.getAttachment(QueryMetadataInterface.class);
    globalTables = vdbMetadata.getAttachment(GlobalTableStore.class);
    if (metadata == null) {
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30489, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30489, this.vdbName, this.vdbVersion));
    }
    TempMetadataAdapter tma = new TempMetadataAdapter(metadata, this.tempTableStore.getMetadataStore());
    tma.setSession(true);
    this.metadata = tma;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) TeiidComponentException(org.teiid.core.TeiidComponentException) TempCapabilitiesFinder(org.teiid.query.metadata.TempCapabilitiesFinder) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface)

Example 18 with TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter in project teiid by teiid.

the class MetaDataProcessor method createProjectedSymbolMetadata.

private Map<Integer, Object>[] createProjectedSymbolMetadata(Command originalCommand) throws TeiidComponentException {
    Map<Integer, Object>[] columnMetadata;
    // Allow command to use temporary metadata
    TempMetadataStore tempMetadata = originalCommand.getTemporaryMetadata();
    if (tempMetadata != null && tempMetadata.getData().size() > 0) {
        TempMetadataAdapter tempFacade = new TempMetadataAdapter(this.metadata, tempMetadata);
        this.metadata = tempFacade;
    }
    List<Expression> projectedSymbols = originalCommand.getProjectedSymbols();
    columnMetadata = new Map[projectedSymbols.size()];
    Iterator<Expression> symbolIter = projectedSymbols.iterator();
    for (int i = 0; symbolIter.hasNext(); i++) {
        Expression symbol = symbolIter.next();
        String shortColumnName = Symbol.getShortName(Symbol.getOutputName(symbol));
        if (symbol instanceof AliasSymbol) {
            symbol = ((AliasSymbol) symbol).getSymbol();
        }
        try {
            columnMetadata[i] = createColumnMetadata(shortColumnName, symbol);
        } catch (QueryMetadataException e) {
            throw new TeiidComponentException(QueryPlugin.Event.TEIID30559, e);
        }
    }
    return columnMetadata;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) Expression(org.teiid.query.sql.symbol.Expression) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) HashMap(java.util.HashMap) Map(java.util.Map) SymbolMap(org.teiid.query.sql.util.SymbolMap) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore)

Example 19 with TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter 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)

Example 20 with TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter in project teiid by teiid.

the class TestProcedureProcessor method helpTestProcess.

public static void helpTestProcess(ProcessorPlan procPlan, List[] expectedResults, ProcessorDataManager dataMgr, QueryMetadataInterface metadata) throws Exception {
    // $NON-NLS-1$
    CommandContext context = new CommandContext("pID", null, null, null, 1);
    if (!(metadata instanceof TempMetadataAdapter)) {
        metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());
    }
    context.setMetadata(metadata);
    TestProcessor.helpProcess(procPlan, context, dataMgr, expectedResults);
    assertNotNull("Expected processing to fail", expectedResults);
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) CommandContext(org.teiid.query.util.CommandContext) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore)

Aggregations

TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)53 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)45 Test (org.junit.Test)32 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)32 Ignore (org.junit.Ignore)21 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 CommandContext (org.teiid.query.util.CommandContext)6 List (java.util.List)4 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)4 TempMetadataID (org.teiid.query.metadata.TempMetadataID)4 Command (org.teiid.query.sql.lang.Command)4 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)4 TeiidComponentException (org.teiid.core.TeiidComponentException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)3 TempCapabilitiesFinder (org.teiid.query.metadata.TempCapabilitiesFinder)3 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 GroupContext (org.teiid.query.sql.lang.GroupContext)3 TempTableStore (org.teiid.query.tempdata.TempTableStore)3 ArrayList (java.util.ArrayList)2