Search in sources :

Example 6 with Vertex

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

the class VertexStreamObserver method onCompleted.

@Override
public void onCompleted() {
    if (!vertexCountList.isEmpty()) {
        for (Map.Entry<ElementId, Integer> entry : vertexCountList.entrySet()) {
            ElementId elementId = entry.getKey();
            MxVertex vertex = new MxVertex(new Vertex(elementId, schema.getElement(elementId.typeId()).getLabel(), Maps.newHashMap(), this.graph.getBaseGraph()), this.graph);
            if (vertexCacheFlag) {
                vertexCache.put(elementId, vertex);
            }
            for (int i = 0; i < entry.getValue(); i++) {
                resultProcessor.process(vertex);
            }
        }
    }
    resultProcessor.finish();
    latch.countDown();
}
Also used : MxVertex(com.alibaba.maxgraph.structure.MxVertex) Vertex(com.alibaba.maxgraph.structure.Vertex) MxVertex(com.alibaba.maxgraph.structure.MxVertex) Map(java.util.Map) ElementId(com.alibaba.maxgraph.sdkcommon.graph.ElementId)

Example 7 with Vertex

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

Example 8 with Vertex

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

the class VertexResponseFunction method apply.

@Override
public Vertex apply(GremlinQuery.VertexResponse nextV) {
    GremlinQuery.VertexId id = nextV.getId();
    CompositeId rId = new CompositeId(id.getId(), id.getTypeId());
    GraphElement type = schema.getElement(id.getTypeId());
    Map<String, Object> properties = RpcProcessorUtils.deserializeProperty(nextV.getPros().toByteArray(), type, schema);
    return new Vertex(rId, type.getLabel(), properties, 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)

Aggregations

Vertex (com.alibaba.maxgraph.structure.Vertex)8 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)5 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)3 IteratorList (com.alibaba.maxgraph.iterator.IteratorList)3 GremlinQuery (com.alibaba.maxgraph.proto.GremlinQuery)3 CompositeId (com.alibaba.maxgraph.sdkcommon.graph.CompositeId)3 MxVertex (com.alibaba.maxgraph.structure.MxVertex)3 EdgeResponseFunction (com.alibaba.maxgraph.iterator.function.EdgeResponseFunction)2 StoreApi (com.alibaba.maxgraph.proto.StoreApi)2 ElementId (com.alibaba.maxgraph.sdkcommon.graph.ElementId)2 Map (java.util.Map)2 VertexResponseFunction (com.alibaba.maxgraph.iterator.function.VertexResponseFunction)1 Edge (com.alibaba.maxgraph.structure.Edge)1 Set (java.util.Set)1