use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.
the class UpdateProcedureResolver method collectDeclareVariable.
private void collectDeclareVariable(DeclareStatement obj, GroupSymbol variables, TempMetadataAdapter metadata, GroupContext externalGroups) throws QueryResolverException, TeiidComponentException {
ElementSymbol variable = obj.getVariable();
String typeName = obj.getVariableType();
GroupSymbol gs = variable.getGroupSymbol();
if (gs == null) {
String outputName = variable.getShortName();
variable.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.VARIABLES));
variable.setOutputName(outputName);
} else {
if (gs.getSchema() != null || !gs.getShortName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) {
// $NON-NLS-1$
handleUnresolvableDeclaration(variable, QueryPlugin.Util.getString("ERR.015.010.0031", new Object[] { ProcedureReservedWords.VARIABLES, variable }));
}
}
boolean exists = false;
try {
ResolverVisitor.resolveLanguageObject(variable, null, externalGroups, metadata);
exists = true;
} catch (QueryResolverException e) {
// ignore, not already defined
}
if (exists) {
// $NON-NLS-1$
handleUnresolvableDeclaration(variable, QueryPlugin.Util.getString("ERR.015.010.0032", variable.getOutputName()));
}
boolean exception = typeName.equalsIgnoreCase(SQLConstants.NonReserved.EXCEPTION);
variable.setType(exception ? DataTypeManager.DefaultDataClasses.OBJECT : DataTypeManager.getDataTypeClass(typeName));
variable.setGroupSymbol(variables);
TempMetadataID id = new TempMetadataID(variable.getName(), exception ? Exception.class : variable.getType());
id.setUpdatable(true);
variable.setMetadataID(id);
// TODO: this will cause the variables group to loose it's cache of resolved symbols
metadata.getMetadataStore().addElementToTempGroup(ProcedureReservedWords.VARIABLES, variable.clone());
}
use of org.teiid.query.sql.symbol.GroupSymbol 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.sql.symbol.GroupSymbol in project teiid by teiid.
the class UpdateResolver method resolveProceduralCommand.
/**
* @see org.teiid.query.resolver.ProcedureContainerResolver#resolveProceduralCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter)
*/
public void resolveProceduralCommand(Command command, TempMetadataAdapter metadata) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
// Cast to known type
Update update = (Update) command;
// Resolve elements and functions
Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
groups.add(update.getGroup());
for (SetClause clause : update.getChangeList().getClauses()) {
ResolverVisitor.resolveLanguageObject(clause.getSymbol(), groups, null, metadata);
}
QueryResolver.resolveSubqueries(command, metadata, groups);
ResolverVisitor.resolveLanguageObject(update, groups, update.getExternalGroupContexts(), metadata);
}
use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.
the class ProcedureContainerResolver method addScalarGroup.
public static GroupSymbol addScalarGroup(String name, TempMetadataStore metadata, GroupContext externalGroups, List<? extends Expression> symbols, boolean[] updatable) {
GroupSymbol variables = new GroupSymbol(name);
externalGroups.addGroup(variables);
TempMetadataID tid = metadata.addTempGroup(name, symbols);
tid.setMetadataType(Type.SCALAR);
int i = 0;
for (TempMetadataID cid : tid.getElements()) {
cid.setMetadataType(Type.SCALAR);
cid.setUpdatable(updatable[i++]);
}
variables.setMetadataID(tid);
return variables;
}
use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.
the class QueryResolver method resolveView.
public static QueryNode resolveView(GroupSymbol virtualGroup, QueryNode qnode, String cacheString, QueryMetadataInterface qmi, boolean logValidation) throws TeiidComponentException, QueryMetadataException, QueryResolverException, QueryValidatorException {
qmi = qmi.getDesignTimeMetadata();
// $NON-NLS-1$
cacheString = "transformation/" + cacheString;
QueryNode cachedNode = (QueryNode) qmi.getFromMetadataCache(virtualGroup.getMetadataID(), cacheString);
if (cachedNode == null) {
Command result = qnode.getCommand();
List<String> bindings = null;
if (result == null) {
try {
result = QueryParser.getQueryParser().parseCommand(qnode.getQuery());
} catch (QueryParserException e) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30065, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30065, virtualGroup));
}
bindings = qnode.getBindings();
} else {
result = (Command) result.clone();
}
if (bindings != null && !bindings.isEmpty()) {
QueryResolver.resolveWithBindingMetadata(result, qmi, qnode, true);
} else {
QueryResolver.resolveCommand(result, qmi, false);
}
Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
validateProjectedSymbols(virtualGroup, qmi, result);
cachedNode = new QueryNode(qnode.getQuery());
cachedNode.setCommand(result);
if (isView(virtualGroup, qmi)) {
String updatePlan = qmi.getUpdatePlan(virtualGroup.getMetadataID());
String deletePlan = qmi.getDeletePlan(virtualGroup.getMetadataID());
String insertPlan = qmi.getInsertPlan(virtualGroup.getMetadataID());
// the elements must be against the view and not the alias
if (virtualGroup.getDefinition() != null) {
GroupSymbol group = new GroupSymbol(virtualGroup.getNonCorrelationName());
group.setMetadataID(virtualGroup.getMetadataID());
virtualGroup = group;
}
List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
UpdateValidator validator = new UpdateValidator(qmi, determineType(insertPlan), determineType(updatePlan), determineType(deletePlan));
validator.validate(result, elements);
UpdateInfo info = validator.getUpdateInfo();
if (logValidation && qmi.groupSupports(virtualGroup.getMetadataID(), SupportConstants.Group.UPDATE)) {
if (info.isInherentInsert() && validator.getInsertReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getInsertReport().getFailureMessage(), SQLConstants.Reserved.INSERT, qmi.getFullName(virtualGroup.getMetadataID())));
}
if (info.isInherentUpdate() && validator.getUpdateReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getUpdateReport().getFailureMessage(), SQLConstants.Reserved.UPDATE, qmi.getFullName(virtualGroup.getMetadataID())));
}
if (info.isInherentDelete() && validator.getDeleteReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getDeleteReport().getFailureMessage(), SQLConstants.Reserved.DELETE, qmi.getFullName(virtualGroup.getMetadataID())));
}
}
cachedNode.setUpdateInfo(info);
}
qmi.addToMetadataCache(virtualGroup.getMetadataID(), cacheString, cachedNode);
}
return cachedNode;
}
Aggregations