Search in sources :

Example 1 with IteratorList

use of com.alibaba.maxgraph.iterator.IteratorList in project GraphScope by alibaba.

the class RemoteProxy method scanEdge.

public Iterator<Edge> scanEdge(Set<String> labelList) {
    Pair<GraphSchema, Long> pair = schemaFetcher.getSchemaSnapshotPair();
    Set<Integer> labelIdList = Sets.newHashSet();
    if (null == labelList || labelList.isEmpty()) {
        labelIdList.add(0);
    } else {
        for (String label : labelList) {
            try {
                labelIdList.add(pair.getLeft().getElement(label).getLabelId());
            } catch (Exception ignored) {
            }
        }
    }
    if (labelIdList.isEmpty()) {
        return new ArrayList<Edge>().iterator();
    }
    List<Iterator<StoreApi.GraphEdgeReponse>> resList = Lists.newArrayList();
    for (int labelId : labelIdList) {
        StoreApi.ScanEdgeRequest.Builder req = StoreApi.ScanEdgeRequest.newBuilder();
        req.setSnapshotId(pair.getRight()).setOffset(0).setLimit(Integer.MAX_VALUE).setTypeId(labelId);
        resList.add(stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).scanEdges(req.build()));
    }
    return new IteratorList<>(resList, new EdgeResponseFunction(pair.getLeft(), this.graph));
}
Also used : EdgeResponseFunction(com.alibaba.maxgraph.iterator.function.EdgeResponseFunction) StoreApi(com.alibaba.maxgraph.proto.StoreApi) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) IteratorList(com.alibaba.maxgraph.iterator.IteratorList) Edge(com.alibaba.maxgraph.structure.Edge)

Example 2 with IteratorList

use of com.alibaba.maxgraph.iterator.IteratorList in project GraphScope by alibaba.

the class RemoteProxy method scan.

public Iterator<Vertex> scan(Set<String> labelList) {
    Pair<GraphSchema, Long> pair = schemaFetcher.getSchemaSnapshotPair();
    Set<Integer> labelIdList = Sets.newHashSet();
    if (null == labelList || labelList.isEmpty()) {
        labelIdList.add(0);
    } else {
        for (String label : labelList) {
            try {
                labelIdList.add(pair.getLeft().getElement(label).getLabelId());
            } catch (Exception ignored) {
            }
        }
    }
    if (labelIdList.isEmpty()) {
        return new ArrayList<Vertex>().iterator();
    }
    List<Iterator<VertexResponse>> resList = Lists.newArrayList();
    VertexScanRequest vertexScanRequest = VertexScanRequest.newBuilder().setTypeId(-1).setOrder(false).build();
    Iterator<VertexResponse> scanResult = GremlinServiceGrpc.newBlockingStub(this.channel).withDeadlineAfter(timeout, TimeUnit.SECONDS).scan(vertexScanRequest);
    resList.add(scanResult);
    return new IteratorList<>(resList, new VertexResponseFunction(pair.getLeft(), this.graph));
}
Also used : Vertex(com.alibaba.maxgraph.structure.Vertex) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) VertexResponseFunction(com.alibaba.maxgraph.iterator.function.VertexResponseFunction) IteratorList(com.alibaba.maxgraph.iterator.IteratorList)

Example 3 with IteratorList

use of com.alibaba.maxgraph.iterator.IteratorList in project GraphScope by alibaba.

the class RemoteProxy method getOutEdges.

public Iterator<Edge> getOutEdges(Set<Vertex> v, String... label) {
    List<Iterator<StoreApi.GraphEdgeReponse>> iterEdgeList = Lists.newArrayList();
    Pair<GraphSchema, Long> schemaPair = schemaFetcher.getSchemaSnapshotPair();
    GraphSchema schema = schemaPair.getLeft();
    long snapshotId = schemaPair.getRight();
    for (Vertex vertex : v) {
        if (label.length == 0) {
            StoreApi.GetOutEdgesRequest.Builder req = StoreApi.GetOutEdgesRequest.newBuilder();
            req.setSnapshotId(snapshotId).setSrcId(vertex.id.id()).setSnapshotId(schemaPair.getRight());
            Iterator<StoreApi.GraphEdgeReponse> edgeResponse = stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).getOutEdges(req.build());
            iterEdgeList.add(edgeResponse);
        } else {
            for (String labelVal : label) {
                try {
                    GraphElement element = schema.getElement(labelVal);
                    int labelId = element.getLabelId();
                    StoreApi.GetOutEdgesRequest.Builder req = StoreApi.GetOutEdgesRequest.newBuilder();
                    req.setSnapshotId(snapshotId).setSrcId(vertex.id.id()).setTypeId(labelId).setSnapshotId(schemaPair.getRight());
                    Iterator<StoreApi.GraphEdgeReponse> edgeResponse = stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).getOutEdges(req.build());
                    iterEdgeList.add(edgeResponse);
                } catch (Exception ignored) {
                }
            }
        }
    }
    return new IteratorList<>(iterEdgeList, new EdgeResponseFunction(schema, this.graph));
}
Also used : Vertex(com.alibaba.maxgraph.structure.Vertex) EdgeResponseFunction(com.alibaba.maxgraph.iterator.function.EdgeResponseFunction) StoreApi(com.alibaba.maxgraph.proto.StoreApi) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) IteratorList(com.alibaba.maxgraph.iterator.IteratorList)

Example 4 with IteratorList

use of com.alibaba.maxgraph.iterator.IteratorList in project GraphScope by alibaba.

the class RemoteProxy method getInEdges.

public Iterator<Edge> getInEdges(Set<Vertex> v, String... label) {
    List<Iterator<StoreApi.GraphEdgeReponse>> iterEdgeList = Lists.newArrayList();
    Pair<GraphSchema, Long> schemaPair = schemaFetcher.getSchemaSnapshotPair();
    GraphSchema schema = schemaPair.getLeft();
    long snapshotId = schemaPair.getRight();
    for (Vertex vertex : v) {
        if (label.length == 0) {
            StoreApi.GetInEdgesRequest.Builder req = StoreApi.GetInEdgesRequest.newBuilder();
            req.setSnapshotId(snapshotId).setDstId(vertex.id.id());
            Iterator<StoreApi.GraphEdgeReponse> edgeResponse = stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).getInEdges(req.build());
            iterEdgeList.add(edgeResponse);
        } else {
            for (String labelVal : label) {
                try {
                    GraphElement element = schema.getElement(labelVal);
                    int labelId = element.getLabelId();
                    StoreApi.GetInEdgesRequest.Builder req = StoreApi.GetInEdgesRequest.newBuilder();
                    req.setSnapshotId(snapshotId).setDstId(vertex.id.id()).setTypeId(labelId);
                    Iterator<StoreApi.GraphEdgeReponse> edgeResponse = stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).getInEdges(req.build());
                    iterEdgeList.add(edgeResponse);
                } catch (Exception ignored) {
                }
            }
        }
    }
    return new IteratorList<>(iterEdgeList, new EdgeResponseFunction(schema, this.graph));
}
Also used : Vertex(com.alibaba.maxgraph.structure.Vertex) EdgeResponseFunction(com.alibaba.maxgraph.iterator.function.EdgeResponseFunction) StoreApi(com.alibaba.maxgraph.proto.StoreApi) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) IteratorList(com.alibaba.maxgraph.iterator.IteratorList)

Example 5 with IteratorList

use of com.alibaba.maxgraph.iterator.IteratorList in project GraphScope by alibaba.

the class RemoteProxy method getVertexBlock.

private Iterator<Vertex> getVertexBlock(Set<ElementId> ids) {
    StoreApi.GetVertexsRequest.Builder b = StoreApi.GetVertexsRequest.newBuilder();
    b.addAllIds(ids.stream().map(ElementId::id).collect(Collectors.toSet())).setSnapshotId(schemaFetcher.getSchemaSnapshotPair().getRight());
    Iterator<VertexResponse> responses = stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).getVertexs(b.build());
    List<Iterator<VertexResponse>> responseList = Lists.newArrayList();
    responseList.add(responses);
    return new IteratorList<>(responseList, new VertexResponseFunction(schemaFetcher.getSchemaSnapshotPair().getLeft(), this.graph));
}
Also used : VertexResponseFunction(com.alibaba.maxgraph.iterator.function.VertexResponseFunction) IteratorList(com.alibaba.maxgraph.iterator.IteratorList)

Aggregations

IteratorList (com.alibaba.maxgraph.iterator.IteratorList)5 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)4 EdgeResponseFunction (com.alibaba.maxgraph.iterator.function.EdgeResponseFunction)3 StoreApi (com.alibaba.maxgraph.proto.StoreApi)3 Vertex (com.alibaba.maxgraph.structure.Vertex)3 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)2 VertexResponseFunction (com.alibaba.maxgraph.iterator.function.VertexResponseFunction)2 Edge (com.alibaba.maxgraph.structure.Edge)1