use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class ResolverVisitor method internalResolveElementSymbol.
private boolean internalResolveElementSymbol(ElementSymbol elementSymbol, String groupContext, String shortCanonicalName, String expectedGroupContext) throws TeiidComponentException, QueryResolverException {
boolean isExternal = false;
boolean groupMatched = false;
GroupContext root = null;
if (groups != null || externalContext != null) {
if (groups != null) {
root = new GroupContext(externalContext, groups);
}
if (root == null) {
isExternal = true;
root = externalContext;
}
} else {
try {
LinkedList<GroupSymbol> matchedGroups = new LinkedList<GroupSymbol>();
if (groupContext != null) {
// assume that this is fully qualified
Object groupID = this.metadata.getGroupID(groupContext);
// No groups specified, so any group is valid
GroupSymbol groupSymbol = new GroupSymbol(groupContext);
groupSymbol.setMetadataID(groupID);
matchedGroups.add(groupSymbol);
}
root = new GroupContext(null, matchedGroups);
} catch (QueryMetadataException e) {
// ignore
}
}
matches.clear();
groupMatches.clear();
while (root != null) {
Collection<GroupSymbol> matchedGroups = ResolverUtil.findMatchingGroups(groupContext, root.getGroups(), metadata);
if (matchedGroups != null && !matchedGroups.isEmpty()) {
groupMatched = true;
resolveAgainstGroups(shortCanonicalName, matchedGroups);
if (matches.size() > 1) {
throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31117, elementSymbol, groupMatches));
}
if (matches.size() == 1) {
break;
}
}
root = root.getParent();
isExternal = true;
}
if (matches.isEmpty()) {
if (groupMatched) {
throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31118, elementSymbol));
}
throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31119, elementSymbol));
}
// copy the match information
ElementSymbol resolvedSymbol = matches.get(0);
GroupSymbol resolvedGroup = groupMatches.get(0);
String oldName = elementSymbol.getOutputName();
if (expectedGroupContext != null && !ResolverUtil.nameMatchesGroup(expectedGroupContext, resolvedGroup.getName())) {
return false;
}
elementSymbol.setIsExternalReference(isExternal);
elementSymbol.setType(resolvedSymbol.getType());
elementSymbol.setMetadataID(resolvedSymbol.getMetadataID());
elementSymbol.setGroupSymbol(resolvedGroup);
elementSymbol.setShortName(resolvedSymbol.getShortName());
if (metadata.useOutputName()) {
elementSymbol.setOutputName(oldName);
}
return true;
}
use of org.teiid.api.exception.query.QueryMetadataException 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.QueryMetadataException in project teiid by teiid.
the class SimpleQueryResolver method resolveCommand.
/**
* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter, boolean)
*/
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
Query query = (Query) command;
resolveWith(metadata, query);
try {
QueryResolverVisitor qrv = new QueryResolverVisitor(query, metadata);
qrv.visit(query);
ResolverVisitor visitor = (ResolverVisitor) qrv.getVisitor();
visitor.throwException(true);
if (visitor.hasUserDefinedAggregate()) {
ExpressionMappingVisitor emv = new ExpressionMappingVisitor(null) {
public Expression replaceExpression(Expression element) {
if (element instanceof Function && !(element instanceof AggregateSymbol) && ((Function) element).isAggregate()) {
Function f = (Function) element;
AggregateSymbol as = new AggregateSymbol(f.getName(), false, f.getArgs(), null);
as.setType(f.getType());
as.setFunctionDescriptor(f.getFunctionDescriptor());
return as;
}
return element;
}
};
PreOrPostOrderNavigator.doVisit(query, emv, PreOrPostOrderNavigator.POST_ORDER);
}
} catch (TeiidRuntimeException e) {
if (e.getCause() instanceof QueryMetadataException) {
throw (QueryMetadataException) e.getCause();
}
if (e.getCause() instanceof QueryResolverException) {
throw (QueryResolverException) e.getCause();
}
if (e.getCause() instanceof TeiidComponentException) {
throw (TeiidComponentException) e.getCause();
}
throw e;
}
if (query.getLimit() != null) {
ResolverUtil.resolveLimit(query.getLimit());
}
if (query.getOrderBy() != null) {
ResolverUtil.resolveOrderBy(query.getOrderBy(), query, metadata);
}
List<Expression> symbols = query.getSelect().getProjectedSymbols();
if (query.getInto() != null) {
GroupSymbol symbol = query.getInto().getGroup();
ResolverUtil.resolveImplicitTempGroup(metadata, symbol, symbols);
} else if (resolveNullLiterals) {
ResolverUtil.resolveNullLiterals(symbols);
}
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class TestCriteriaCapabilityValidatorVisitor method helpTestVisitor.
public void helpTestVisitor(String sql, Object modelID, TransformationMetadata metadata, CapabilitiesFinder capFinder, boolean isValid, boolean expectException) throws Exception {
try {
Criteria criteria = QueryParser.getQueryParser().parseCriteria(sql);
QueryResolver.resolveCriteria(criteria, metadata);
// $NON-NLS-1$
assertEquals("Got incorrect isValid flag", isValid, CriteriaCapabilityValidatorVisitor.canPushLanguageObject(criteria, modelID, metadata, capFinder, null));
} catch (QueryMetadataException e) {
if (!expectException) {
throw new RuntimeException(e);
}
}
}
Aggregations