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