Search in sources :

Example 1 with ListIterator

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

the class GraphTransaction method queryEdgesFromBackend.

protected Iterator<HugeEdge> queryEdgesFromBackend(Query query) {
    assert query.resultType().isEdge();
    QueryResults<BackendEntry> results = this.query(query);
    Iterator<BackendEntry> entries = results.iterator();
    Iterator<HugeEdge> edges = new FlatMapperIterator<>(entries, entry -> {
        // Edges are in a vertex
        HugeVertex vertex = this.parseEntry(entry);
        if (vertex == null) {
            return null;
        }
        if (query.idsSize() == 1) {
            assert vertex.getEdges().size() == 1;
        }
        /*
             * Copy to avoid ConcurrentModificationException when removing edge
             * because HugeEdge.remove() will update edges in owner vertex
             */
        return new ListIterator<>(ImmutableList.copyOf(vertex.getEdges()));
    });
    edges = this.filterExpiredResultFromFromBackend(query, edges);
    if (!this.store().features().supportsQuerySortByInputIds()) {
        // There is no id in BackendEntry, so sort after deserialization
        edges = results.keepInputOrderIfNeeded(edges);
    }
    return edges;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) FlatMapperIterator(com.baidu.hugegraph.iterator.FlatMapperIterator) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) ListIterator(com.baidu.hugegraph.iterator.ListIterator) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Aggregations

BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)1 FlatMapperIterator (com.baidu.hugegraph.iterator.FlatMapperIterator)1 ListIterator (com.baidu.hugegraph.iterator.ListIterator)1 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)1 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)1