Search in sources :

Example 1 with ExpandNode

use of org.teiid.olingo.service.TeiidServiceHandler.ExpandNode in project teiid by teiid.

the class ODataSQLBuilder method processExpand.

private void processExpand(List<ExpandNode> expand, DocumentNode resource, Query outerQuery, int expandLevel) throws TeiidException {
    if (expand.isEmpty()) {
        return;
    }
    checkExpandLevel(expandLevel);
    for (ExpandNode expandNode : expand) {
        ExpandDocumentNode expandResource = ExpandDocumentNode.buildExpand(expandNode.navigationProperty, this.metadata, this.odata, this.nameGenerator, this.aliasedGroups, getUriInfo(), this.parseService, this.context);
        OrderBy expandOrder = expandResource.addDefaultOrderBy();
        expandResource.addAllColumns(false);
        resource.addExpand(expandResource);
        Query query = expandResource.buildQuery();
        processExpand(expandNode.children, expandResource, query, expandLevel + 1);
        buildAggregateQuery(resource, outerQuery, expandResource, expandOrder, query, expandNode.navigationProperty);
    }
}
Also used : ExpandNode(org.teiid.olingo.service.TeiidServiceHandler.ExpandNode)

Example 2 with ExpandNode

use of org.teiid.olingo.service.TeiidServiceHandler.ExpandNode in project teiid by teiid.

the class ODataSQLBuilder method buildExpandGraph.

private void buildExpandGraph(HashSet<String> seen, List<ExpandNode> starExpand, EdmEntityType edmEntityType, int remainingLevels) {
    for (String name : edmEntityType.getNavigationPropertyNames()) {
        if (seen != null && seen.contains(name)) {
            // explicit expand supersedes
            continue;
        }
        EdmNavigationProperty property = edmEntityType.getNavigationProperty(name);
        ExpandNode en = new ExpandNode();
        en.navigationProperty = property;
        starExpand.add(en);
        if (remainingLevels > 0) {
            buildExpandGraph(null, en.children, property.getType(), remainingLevels - 1);
        }
    }
}
Also used : ExpandNode(org.teiid.olingo.service.TeiidServiceHandler.ExpandNode) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty)

Example 3 with ExpandNode

use of org.teiid.olingo.service.TeiidServiceHandler.ExpandNode in project teiid by teiid.

the class ODataSQLBuilder method processExpandOption.

private void processExpandOption(ExpandOption option, DocumentNode node, Query outerQuery, int expandLevel, Integer cyclicLevel) throws TeiidException {
    checkExpandLevel(expandLevel);
    int starLevels = 0;
    HashSet<String> seen = new HashSet<String>();
    for (ExpandItem ei : option.getExpandItems()) {
        if (ei.getSearchOption() != null) {
            throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16035, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16035));
        }
        Integer levels = null;
        if (cyclicLevel != null) {
            levels = cyclicLevel - 1;
        } else if (ei.getLevelsOption() != null) {
            if (ei.getLevelsOption().isMax()) {
                levels = MAX_EXPAND_LEVEL - expandLevel + 1;
            } else {
                levels = ei.getLevelsOption().getValue();
                checkExpandLevel(expandLevel + levels - 1);
            }
        }
        ExpandSQLBuilder esb = new ExpandSQLBuilder(ei);
        EdmNavigationProperty property = esb.getNavigationProperty();
        if (property == null) {
            if (ei.isStar()) {
                if (starLevels > 0) {
                    throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, // $NON-NLS-1$
                    ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, "*"));
                }
                if (levels != null) {
                    starLevels = levels;
                } else {
                    starLevels = 1;
                }
                continue;
            }
            throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16057, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16057));
        }
        if (!seen.add(property.getName())) {
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, property.getName()));
        }
        // always pass in the root as the parent as that seems to be the definition of the current context
        // if instead it should refer to the parent expands, then we would pass in the node instead
        ExpandDocumentNode expandResource = ExpandDocumentNode.buildExpand(property, this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), this.parseService, this.context);
        node.addExpand(expandResource);
        // process $filter
        if (ei.getFilterOption() != null) {
            Expression expandCriteria = processFilterOption(ei.getFilterOption(), expandResource);
            expandResource.addCriteria(expandCriteria);
        }
        OrderBy expandOrder = null;
        if (ei.getOrderByOption() != null) {
            expandOrder = new OrderBy();
            processOrderBy(expandOrder, ei.getOrderByOption().getOrders(), expandResource);
        } else {
            expandOrder = expandResource.addDefaultOrderBy();
        }
        // process $select
        processSelectOption(ei.getSelectOption(), expandResource, this.reference);
        if (ei.getSkipOption() != null) {
            expandResource.setSkip(ei.getSkipOption().getValue());
        }
        if (ei.getTopOption() != null) {
            expandResource.setTop(ei.getTopOption().getValue());
        }
        Query query = expandResource.buildQuery();
        if (ei.getExpandOption() != null) {
            processExpandOption(ei.getExpandOption(), expandResource, query, expandLevel + 1, null);
        } else if (levels != null) {
            // self reference check
            if (!property.getType().getFullQualifiedName().equals(node.getEdmEntityType().getFullQualifiedName())) {
                throw new TeiidProcessingException(ODataPlugin.Event.TEIID16060, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16060, node.getEdmEntityType().getFullQualifiedName(), property.getType().getFullQualifiedName()));
            }
            if (levels > 1) {
                ExpandOptionImpl eoi = new ExpandOptionImpl();
                eoi.addExpandItem(ei);
                processExpandOption(eoi, expandResource, query, expandLevel + 1, levels);
            }
        }
        buildAggregateQuery(node, outerQuery, expandResource, expandOrder, query, property);
    }
    if (starLevels > 0) {
        List<ExpandNode> starExpand = new ArrayList<TeiidServiceHandler.ExpandNode>();
        EdmEntityType edmEntityType = node.getEdmEntityType();
        buildExpandGraph(seen, starExpand, edmEntityType, starLevels - 1);
        if (!starExpand.isEmpty()) {
            processExpand(starExpand, node, outerQuery, expandLevel);
        }
    }
}
Also used : ExpandOptionImpl(org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl) ExpandNode(org.teiid.olingo.service.TeiidServiceHandler.ExpandNode) ArrayList(java.util.ArrayList) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Expression(org.teiid.query.sql.symbol.Expression) HashSet(java.util.HashSet)

Aggregations

ExpandNode (org.teiid.olingo.service.TeiidServiceHandler.ExpandNode)3 EdmNavigationProperty (org.apache.olingo.commons.api.edm.EdmNavigationProperty)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)1 ExpandOptionImpl (org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 SubqueryHint (org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)1 Expression (org.teiid.query.sql.symbol.Expression)1