Search in sources :

Example 1 with QueryInfo

use of org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo in project janusgraph by JanusGraph.

the class JanusGraphStep method buildGlobalGraphCentricQuery.

public GraphCentricQuery buildGlobalGraphCentricQuery() {
    if (ids == null || ids.length > 0) {
        return null;
    }
    if (globalQuery != null) {
        return globalQuery;
    }
    if (hasLocalContainers.isEmpty()) {
        Map<List<HasContainer>, QueryInfo> containers = new LinkedHashMap<>();
        containers.put(new ArrayList<>(), new QueryInfo(new ArrayList<>(), 0, BaseQuery.NO_LIMIT));
        hasLocalContainers.put(null, containers);
    }
    tx = JanusGraphTraversalUtil.getTx(traversal);
    globalQuery = buildGlobalGraphCentricQuery(tx, queryProfiler);
    return globalQuery;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) QueryInfo(org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with QueryInfo

use of org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo in project janusgraph by JanusGraph.

the class JanusGraphStep method addLocalHasContainersConvertingAndPContainers.

@Override
public List<HasContainer> addLocalHasContainersConvertingAndPContainers(TraversalParent parent, List<HasContainer> unconvertedHasContainers) {
    List<HasContainer> localHasContainers = new ArrayList<>(unconvertedHasContainers.size());
    for (HasContainer hasContainer : unconvertedHasContainers) {
        localHasContainers.add(JanusGraphPredicateUtils.convert(hasContainer));
    }
    Map<List<HasContainer>, QueryInfo> hasContainers = hasLocalContainers.computeIfAbsent(parent.asStep().getId(), k -> new LinkedHashMap<>());
    hasContainers.put(localHasContainers, new QueryInfo(new ArrayList<>(), 0, BaseQuery.NO_LIMIT));
    return localHasContainers;
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) QueryInfo(org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo)

Example 3 with QueryInfo

use of org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo in project janusgraph by JanusGraph.

the class JanusGraphStep method addLocalHasContainersSplittingAndPContainers.

@Override
public List<HasContainer> addLocalHasContainersSplittingAndPContainers(TraversalParent parent, Iterable<HasContainer> hasContainers) {
    List<HasContainer> localHasContainers = new ArrayList<>();
    for (HasContainer hasContainer : hasContainers) {
        HasStepFolder.splitAndP(localHasContainers, hasContainer);
    }
    Map<List<HasContainer>, QueryInfo> containers = hasLocalContainers.computeIfAbsent(parent.asStep().getId(), k -> new LinkedHashMap<>());
    containers.put(localHasContainers, new QueryInfo(new ArrayList<>(), 0, BaseQuery.NO_LIMIT));
    return localHasContainers;
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) QueryInfo(org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo)

Example 4 with QueryInfo

use of org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo in project janusgraph by JanusGraph.

the class JanusGraphStep method buildGlobalGraphCentricQuery.

private GraphCentricQuery buildGlobalGraphCentricQuery(final JanusGraphTransaction tx, final QueryProfiler globalQueryProfiler) {
    Integer limit = null;
    for (Map<List<HasContainer>, QueryInfo> containers : hasLocalContainers.values()) {
        for (QueryInfo queryInfo : containers.values()) {
            if (queryInfo.getLowLimit() > 0 || orders.isEmpty() && !queryInfo.getOrders().isEmpty()) {
                return null;
            }
            final int currentHighLimit = queryInfo.getHighLimit();
            if (limit == null) {
                limit = currentHighLimit;
            } else if (currentHighLimit < highLimit && !limit.equals(currentHighLimit)) {
                return null;
            }
        }
    }
    final JanusGraphQuery query = tx.query();
    for (Map<List<HasContainer>, QueryInfo> lc : hasLocalContainers.values()) {
        List<JanusGraphQuery> localQueries = new ArrayList<>(lc.size());
        for (final List<HasContainer> localContainers : lc.keySet()) {
            final JanusGraphQuery localQuery = tx.query();
            addConstraint(localQuery, localContainers);
            localQueries.add(localQuery);
        }
        query.or(localQueries);
    }
    for (final OrderEntry order : orders) query.orderBy(order.key, order.order);
    query.limit(Math.min(limit, highLimit));
    return buildGraphCentricQuery(query, globalQueryProfiler);
}
Also used : JanusGraphQuery(org.janusgraph.core.JanusGraphQuery) ArrayList(java.util.ArrayList) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ArrayList(java.util.ArrayList) List(java.util.List) QueryInfo(org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo)

Aggregations

ArrayList (java.util.ArrayList)4 List (java.util.List)4 QueryInfo (org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo)4 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)3 LinkedHashMap (java.util.LinkedHashMap)1 JanusGraphQuery (org.janusgraph.core.JanusGraphQuery)1