Search in sources :

Example 1 with ResolverVisitor

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);
    }
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) ExpressionMappingVisitor(org.teiid.query.sql.visitor.ExpressionMappingVisitor) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) ResolverVisitor(org.teiid.query.resolver.util.ResolverVisitor) TeiidComponentException(org.teiid.core.TeiidComponentException)

Aggregations

QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)1 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 ResolverVisitor (org.teiid.query.resolver.util.ResolverVisitor)1 ExpressionMappingVisitor (org.teiid.query.sql.visitor.ExpressionMappingVisitor)1