Search in sources :

Example 16 with TempMetadataStore

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

use of org.teiid.query.metadata.TempMetadataStore 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 18 with TempMetadataStore

use of org.teiid.query.metadata.TempMetadataStore 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 19 with TempMetadataStore

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

Example 20 with TempMetadataStore

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

the class TestProcErrors method testNestedBeginAtomicException.

@Test
public void testNestedBeginAtomicException() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.example1Cached();
    String query = "BEGIN atomic\n" + " declare string VARIABLES.RESULT;\n" + " begin atomic select 1/0; exception e end end";
    ProcessorPlan plan = getProcedurePlan(query, tm);
    // Create expected results
    List<?>[] expected = new List[0];
    // $NON-NLS-1$
    CommandContext context = new CommandContext("pID", null, null, null, 1);
    QueryMetadataInterface metadata = new TempMetadataAdapter(tm, new TempMetadataStore());
    context.setMetadata(metadata);
    TransactionContext tc = new TransactionContext();
    Transaction txn = Mockito.mock(Transaction.class);
    tc.setTransaction(txn);
    tc.setTransactionType(Scope.REQUEST);
    TransactionService ts = Mockito.mock(TransactionService.class);
    context.setTransactionService(ts);
    context.setTransactionContext(tc);
    TestProcessor.helpProcess(plan, context, new HardcodedDataManager(), expected);
    Mockito.verify(txn, Mockito.times(3)).setRollbackOnly();
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) TransactionService(org.teiid.dqp.service.TransactionService) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Transaction(javax.transaction.Transaction) TransactionContext(org.teiid.dqp.service.TransactionContext) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Aggregations

TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)52 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)45 Test (org.junit.Test)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)32 Ignore (org.junit.Ignore)21 TempMetadataID (org.teiid.query.metadata.TempMetadataID)6 CommandContext (org.teiid.query.util.CommandContext)6 List (java.util.List)5 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)5 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)5 Command (org.teiid.query.sql.lang.Command)5 GroupContext (org.teiid.query.sql.lang.GroupContext)5 Expression (org.teiid.query.sql.symbol.Expression)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)4 ArrayList (java.util.ArrayList)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)3 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)3 LinkedList (java.util.LinkedList)2