Search in sources :

Example 6 with MapperIterator

use of com.baidu.hugegraph.iterator.MapperIterator in project incubator-hugegraph by apache.

the class GraphTransaction method queryEdgesByIds.

protected Iterator<Edge> queryEdgesByIds(Object[] edgeIds, boolean verifyId) {
    Query.checkForceCapacity(edgeIds.length);
    // NOTE: allowed duplicated edges if query by duplicated ids
    List<Id> ids = InsertionOrderUtil.newList();
    Map<Id, HugeEdge> edges = new HashMap<>(edgeIds.length);
    IdQuery query = new IdQuery(HugeType.EDGE);
    for (Object edgeId : edgeIds) {
        HugeEdge edge;
        EdgeId id = HugeEdge.getIdValue(edgeId, !verifyId);
        if (id == null) {
            continue;
        }
        if (id.direction() == Directions.IN) {
            id = id.switchDirection();
        }
        if (this.removedEdges.containsKey(id)) {
            // The record has been deleted
            continue;
        } else if ((edge = this.addedEdges.get(id)) != null || (edge = this.updatedEdges.get(id)) != null) {
            if (edge.expired()) {
                continue;
            }
            // Found from local tx
            edges.put(edge.id(), edge);
        } else {
            // Prepare to query from backend store
            query.query(id);
        }
        ids.add(id);
    }
    if (!query.empty()) {
        // Query from backend store
        if (edges.isEmpty() && query.idsSize() == ids.size()) {
            /*
                 * Sort at the lower layer and return directly if there is no
                 * local vertex and duplicated id.
                 */
            Iterator<HugeEdge> it = this.queryEdgesFromBackend(query);
            @SuppressWarnings({ "unchecked", "rawtypes" }) Iterator<Edge> r = (Iterator) it;
            return r;
        }
        query.mustSortByInput(false);
        Iterator<HugeEdge> it = this.queryEdgesFromBackend(query);
        QueryResults.fillMap(it, edges);
    }
    return new MapperIterator<>(ids.iterator(), id -> {
        Edge edge = edges.get(id);
        return edge;
    });
}
Also used : MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) FlatMapperIterator(com.baidu.hugegraph.iterator.FlatMapperIterator) BatchMapperIterator(com.baidu.hugegraph.iterator.BatchMapperIterator) HashMap(java.util.HashMap) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) ListIterator(com.baidu.hugegraph.iterator.ListIterator) MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) ExtendableIterator(com.baidu.hugegraph.iterator.ExtendableIterator) FlatMapperIterator(com.baidu.hugegraph.iterator.FlatMapperIterator) LimitIterator(com.baidu.hugegraph.iterator.LimitIterator) CloseableIterator(org.apache.tinkerpop.gremlin.structure.util.CloseableIterator) BatchMapperIterator(com.baidu.hugegraph.iterator.BatchMapperIterator) FilterIterator(com.baidu.hugegraph.iterator.FilterIterator) Iterator(java.util.Iterator) IdQuery(com.baidu.hugegraph.backend.query.IdQuery) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Aggregations

MapperIterator (com.baidu.hugegraph.iterator.MapperIterator)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)3 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)3 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 Id (com.baidu.hugegraph.backend.id.Id)2 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)2 BatchMapperIterator (com.baidu.hugegraph.iterator.BatchMapperIterator)2 FlatMapperIterator (com.baidu.hugegraph.iterator.FlatMapperIterator)2 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)2 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 HugeGraph (com.baidu.hugegraph.HugeGraph)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 ExtendableIterator (com.baidu.hugegraph.iterator.ExtendableIterator)1