Search in sources :

Example 1 with Edge

use of com.alibaba.maxgraph.structure.Edge 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 Edge

use of com.alibaba.maxgraph.structure.Edge in project GraphScope by alibaba.

the class EdgeResponseFunction method apply.

@Override
public Edge apply(StoreApi.GraphEdgeReponse edgeReponse) {
    CompositeId eid = new CompositeId(edgeReponse.getEdgeId(), edgeReponse.getTypeId());
    GraphElement element = schema.getElement(eid.typeId());
    String label = element.getLabel();
    Map<String, Object> properties = RpcProcessorUtils.deserializeProperty(edgeReponse.getPros().toByteArray(), element, schema);
    GremlinQuery.VertexId srcId = edgeReponse.getSrcId();
    GremlinQuery.VertexId dstId = edgeReponse.getDstId();
    Iterator<Vertex> vertexIterator = graph.getVertex(Sets.newHashSet(new CompositeId(srcId.getId(), srcId.getTypeId()), new CompositeId(dstId.getId(), dstId.getTypeId())));
    Vertex srcVertex = null, dstVertex = null;
    while (vertexIterator.hasNext()) {
        Vertex vertex = vertexIterator.next();
        if (vertex.id.id() == srcId.getId()) {
            srcVertex = vertex;
        }
        if (vertex.id.id() == dstId.getId()) {
            dstVertex = vertex;
        }
    }
    if (null == srcVertex) {
        try {
            GraphElement graphElement = schema.getElement(srcId.getTypeId());
            srcVertex = new Vertex(new CompositeId(srcId.getId(), srcId.getTypeId()), graphElement.getLabel(), Maps.newHashMap(), graph);
        } catch (Exception ignored) {
            srcVertex = new Vertex(new CompositeId(srcId.getId(), srcId.getTypeId()), "", Maps.newHashMap(), graph);
        }
    }
    if (null == dstVertex) {
        try {
            GraphElement graphElement = schema.getElement(dstId.getTypeId());
            dstVertex = new Vertex(new CompositeId(dstId.getId(), dstId.getTypeId()), graphElement.getLabel(), Maps.newHashMap(), graph);
        } catch (Exception ignored) {
            dstVertex = new Vertex(new CompositeId(dstId.getId(), dstId.getTypeId()), "", Maps.newHashMap(), graph);
        }
    }
    return new Edge(eid, label, properties, srcVertex, dstVertex, this.graph);
}
Also used : Vertex(com.alibaba.maxgraph.structure.Vertex) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) CompositeId(com.alibaba.maxgraph.sdkcommon.graph.CompositeId) GremlinQuery(com.alibaba.maxgraph.proto.GremlinQuery) Edge(com.alibaba.maxgraph.structure.Edge)

Aggregations

Edge (com.alibaba.maxgraph.structure.Edge)2 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 IteratorList (com.alibaba.maxgraph.iterator.IteratorList)1 EdgeResponseFunction (com.alibaba.maxgraph.iterator.function.EdgeResponseFunction)1 GremlinQuery (com.alibaba.maxgraph.proto.GremlinQuery)1 StoreApi (com.alibaba.maxgraph.proto.StoreApi)1 CompositeId (com.alibaba.maxgraph.sdkcommon.graph.CompositeId)1 Vertex (com.alibaba.maxgraph.structure.Vertex)1