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);
}
}
}
}
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;
}
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());
}
}
}
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);
}
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();
}
Aggregations