use of org.teiid.query.resolver.util.ResolverVisitor 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);
}
}
Aggregations