Search in sources :

Example 1 with PostOrderNavigator

use of org.teiid.query.sql.navigator.PostOrderNavigator in project teiid by teiid.

the class ResolverVisitor method resolveLanguageObject.

public static void resolveLanguageObject(LanguageObject obj, Collection<GroupSymbol> groups, GroupContext externalContext, QueryMetadataInterface metadata) throws TeiidComponentException, QueryResolverException {
    if (obj == null) {
        return;
    }
    // Resolve elements, deal with errors
    final ResolverVisitor elementsVisitor = new ResolverVisitor(metadata, groups, externalContext);
    // special handling for is distinct - we must resolve as both element and group
    // until we generalize the notion of a scalar group reference as an "elementsymbol"
    PostOrderNavigator nav = new PostOrderNavigator(elementsVisitor) {

        @Override
        public void visit(IsDistinctCriteria obj) {
            obj.setLeftRowValue(resolveAsGroup(obj.getLeftRowValue()));
            obj.setRightRowValue(resolveAsGroup(obj.getRightRowValue()));
            super.visit(obj);
        }

        private LanguageObject resolveAsGroup(LanguageObject rowValue) {
            if (rowValue instanceof ElementSymbol) {
                ElementSymbol es = (ElementSymbol) rowValue;
                if (es.getMetadataID() == null) {
                    try {
                        elementsVisitor.resolveElementSymbol(es);
                    } catch (QueryResolverException | TeiidComponentException e) {
                        GroupSymbol gs = new GroupSymbol(es.getName());
                        try {
                            ResolverUtil.resolveGroup(gs, metadata);
                            rowValue = gs;
                        } catch (QueryResolverException | TeiidComponentException e1) {
                        }
                    }
                }
            }
            return rowValue;
        }
    };
    obj.acceptVisitor(nav);
    elementsVisitor.throwException(true);
}
Also used : PostOrderNavigator(org.teiid.query.sql.navigator.PostOrderNavigator) TeiidComponentException(org.teiid.core.TeiidComponentException) LanguageObject(org.teiid.query.sql.LanguageObject) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Aggregations

QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 LanguageObject (org.teiid.query.sql.LanguageObject)1 PostOrderNavigator (org.teiid.query.sql.navigator.PostOrderNavigator)1