use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ProcedureContainerResolver method expandCommand.
/**
* Expand a command by finding and attaching all subcommands to the command. If
* some initial resolution must be done for this to be accomplished, that is ok,
* but it should be kept to a minimum.
* @param command The command to expand
* @param useMetadataCommands True if resolver should use metadata commands to completely resolve
* @param metadata Metadata access
* @param analysis The analysis record that will be filled in if doing annotation.
*
* @throws QueryMetadataException If there is a metadata problem
* @throws QueryResolverException If the query cannot be resolved
* @throws TeiidComponentException If there is an internal error
*/
public Command expandCommand(ProcedureContainer procCommand, QueryMetadataInterface metadata, AnalysisRecord analysis) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
// Resolve group so we can tell whether it is an update procedure
GroupSymbol group = procCommand.getGroup();
Command subCommand = null;
String plan = getPlan(metadata, procCommand);
if (plan == null) {
return null;
}
QueryParser parser = QueryParser.getQueryParser();
try {
subCommand = parser.parseProcedure(plan, !(procCommand instanceof StoredProcedure));
} catch (QueryParserException e) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30060, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30060, group, procCommand.getClass().getSimpleName()));
}
return subCommand;
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class QueryResolver method resolveCommand.
public static TempMetadataStore resolveCommand(Command currentCommand, QueryMetadataInterface metadata, boolean resolveNullLiterals) throws QueryResolverException, TeiidComponentException {
// $NON-NLS-1$
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_QUERY_RESOLVER, new Object[] { "Resolving command", currentCommand });
TempMetadataAdapter resolverMetadata = null;
try {
TempMetadataStore discoveredMetadata = currentCommand.getTemporaryMetadata();
if (discoveredMetadata == null) {
discoveredMetadata = new TempMetadataStore();
currentCommand.setTemporaryMetadata(discoveredMetadata);
}
resolverMetadata = new TempMetadataAdapter(metadata, discoveredMetadata);
// Resolve external groups for command
Collection<GroupSymbol> externalGroups = currentCommand.getAllExternalGroups();
for (GroupSymbol extGroup : externalGroups) {
Object metadataID = extGroup.getMetadataID();
// TODO: this is mainly for XML resolving since it sends external groups in unresolved
if (metadataID == null || (!(extGroup.getMetadataID() instanceof TempMetadataID) && discoveredMetadata.getTempGroupID(extGroup.getName()) != null)) {
boolean missing = metadataID == null;
metadataID = resolverMetadata.getGroupID(extGroup.getName());
if (missing) {
extGroup.setMetadataID(metadataID);
} else {
// we shouldn't modify the existing, just add a shadow group
GroupSymbol gs = extGroup.clone();
gs.setMetadataID(metadataID);
currentCommand.getExternalGroupContexts().addGroup(gs);
}
}
}
CommandResolver resolver = chooseResolver(currentCommand, resolverMetadata);
// Resolve this command
resolver.resolveCommand(currentCommand, resolverMetadata, resolveNullLiterals);
} catch (QueryMetadataException e) {
throw new QueryResolverException(e);
}
// Flag that this command has been resolved.
currentCommand.setIsResolved(true);
return resolverMetadata.getMetadataStore();
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class AlterResolver method resolveCommand.
@Override
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
Alter<? extends Command> alter = (Alter<? extends Command>) command;
ResolverUtil.resolveGroup(alter.getTarget(), metadata);
int type = Command.TYPE_QUERY;
boolean viewTarget = true;
if (alter instanceof AlterTrigger) {
TriggerEvent event = ((AlterTrigger) alter).getEvent();
switch(event) {
case DELETE:
type = Command.TYPE_DELETE;
break;
case INSERT:
type = Command.TYPE_INSERT;
break;
case UPDATE:
type = Command.TYPE_UPDATE;
break;
}
if (((AlterTrigger) alter).isAfter()) {
viewTarget = false;
}
} else if (alter instanceof AlterProcedure) {
type = Command.TYPE_STORED_PROCEDURE;
viewTarget = false;
}
if (viewTarget && !QueryResolver.isView(alter.getTarget(), metadata)) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30116, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30116, alter.getTarget()));
}
if (alter.getDefinition() != null) {
QueryResolver.resolveCommand(alter.getDefinition(), alter.getTarget(), type, metadata.getDesignTimeMetadata(), false);
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class InsertResolver method resolveTypes.
/**
* @param insert
* @param values
* @param usingQuery
* @throws QueryResolverException
*/
public void resolveTypes(Insert insert, TempMetadataAdapter metadata, List values, boolean usingQuery) throws QueryResolverException {
List newValues = new ArrayList(values.size());
// check that # of variables == # of values
if (values.size() != insert.getVariables().size()) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30127, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30127, insert.getVariables().size(), values.size()));
}
Iterator valueIter = values.iterator();
Iterator<ElementSymbol> varIter = insert.getVariables().iterator();
while (valueIter.hasNext()) {
// Walk through both elements and expressions, which should match up
Expression expression = (Expression) valueIter.next();
ElementSymbol element = varIter.next();
if (expression.getType() == null) {
ResolverUtil.setDesiredType(SymbolMap.getExpression(expression), element.getType(), insert);
}
if (element.getType() != null && expression.getType() != null) {
String elementTypeName = DataTypeManager.getDataTypeName(element.getType());
if (!usingQuery) {
newValues.add(ResolverUtil.convertExpression(expression, elementTypeName, metadata));
} else if (element.getType() != expression.getType() && !DataTypeManager.isImplicitConversion(DataTypeManager.getDataTypeName(expression.getType()), DataTypeManager.getDataTypeName(element.getType()))) {
// TODO: a special case here is a projected literal
throw new QueryResolverException(QueryPlugin.Event.TEIID30128, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30128, new Object[] { expression, expression.getType().getName(), element, element.getType().getName() }));
}
} else if (element.getType() == null && expression.getType() != null) {
element.setType(expression.getType());
newValues.add(expression);
} else {
// $NON-NLS-1$
Assertion.failed("Cannot determine element or expression type");
}
}
if (!usingQuery) {
insert.setValues(newValues);
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class SetQueryResolver method resolveSetQuery.
public void resolveSetQuery(TempMetadataAdapter metadata, boolean resolveNullLiterals, SetQuery setQuery, QueryCommand firstCommand, QueryCommand rightCommand) throws QueryResolverException, QueryMetadataException, TeiidComponentException {
List<Expression> firstProject = firstCommand.getProjectedSymbols();
List<Class<?>> firstProjectTypes = new ArrayList<Class<?>>();
for (Expression symbol : firstProject) {
firstProjectTypes.add(symbol.getType());
}
if (firstProject.size() != rightCommand.getProjectedSymbols().size()) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30147, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30147, setQuery.getOperation()));
}
checkSymbolTypes(firstProjectTypes, rightCommand.getProjectedSymbols());
if (resolveNullLiterals) {
for (int i = 0; i < firstProjectTypes.size(); i++) {
Class<?> clazz = firstProjectTypes.get(i);
if (clazz == null || clazz.equals(DataTypeManager.DefaultDataClasses.NULL)) {
firstProjectTypes.set(i, DataTypeManager.DefaultDataClasses.STRING);
}
}
}
setQuery.setProjectedTypes(firstProjectTypes, metadata.getMetadata());
// ORDER BY clause
if (setQuery.getOrderBy() != null) {
// order by elements must use the short name of the projected symbols
ResolverUtil.resolveOrderBy(setQuery.getOrderBy(), setQuery, metadata);
}
setProjectedTypes(setQuery, firstProjectTypes, metadata.getMetadata());
if (setQuery.getLimit() != null) {
ResolverUtil.resolveLimit(setQuery.getLimit());
}
setQuery.setTemporaryMetadata(firstCommand.getTemporaryMetadata().clone());
}
Aggregations