Search in sources :

Example 1 with MxVertex

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

the class GremlinResultTransform method queryVertices.

private void queryVertices(GraphSchema schema, Context context, int batchSize, List<Object> resultList, Map<ElementId, Integer> vertexCountList, Map<Integer, Set<ElementId>> classified, Map<CompositeId, Map<String, Object>> existPropMap, RpcProcessorType rpcProcessorType, String queryId) {
    logger.info("Start to fetch detail for vertex in query " + queryId);
    Map<Integer, Map<ElementId, Integer>> classifiedList = Maps.newHashMap();
    if (classified.size() == 1) {
        int key = Lists.newArrayList(classified.keySet()).get(0);
        classifiedList.put(key, vertexCountList);
    } else {
        for (Map.Entry<Integer, Set<ElementId>> entry : classified.entrySet()) {
            Map<ElementId, Integer> classifiedCountList = Maps.newHashMap();
            for (ElementId elementId : entry.getValue()) {
                classifiedCountList.put(elementId, vertexCountList.remove(elementId));
            }
            classifiedList.put(entry.getKey(), classifiedCountList);
        }
    }
    if (null == rpcProcessorType) {
        remoteRpcConnector.queryVertices(classifiedList, schema, graph, context, batchSize, resultList, vertexCacheFlag, existPropMap);
    } else {
        remoteRpcConnector.queryVertices(classifiedList, schema, graph, context, batchSize, resultList, vertexCacheFlag, rpcProcessorType, existPropMap);
    }
    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);
            }
            if (null != resultList) {
                resultList.add(vertex);
            }
            if (rpcProcessorType != RpcProcessorType.MEMORY) {
                remoteRpcProcessor.process(vertex);
            }
        }
    }
    logger.info("Fetch detail for vertex in query " + queryId + " finish");
}
Also used : MxVertex(com.alibaba.maxgraph.structure.MxVertex) Vertex(com.alibaba.maxgraph.structure.Vertex) Set(java.util.Set) MxVertex(com.alibaba.maxgraph.structure.MxVertex) Map(java.util.Map) ElementId(com.alibaba.maxgraph.sdkcommon.graph.ElementId)

Example 2 with MxVertex

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

the class VertexStreamObserver method onNext.

@Override
public void onNext(GremlinQuery.VertexResponse vertexResponse) {
    GremlinQuery.VertexId id = vertexResponse.getId();
    CompositeId rId = new CompositeId(id.getId(), id.getTypeId());
    GraphElement type = schema.getElement(id.getTypeId());
    Map<String, Object> properties = null;
    try {
        properties = RpcProcessorUtils.deserializeProperty(vertexResponse.getPros().toByteArray(), type, schema);
    } catch (Exception e) {
        throw new RuntimeException("query properties for vertex=>" + rId.toString() + " fail", e);
    }
    Map<String, Object> existProp = existPropMap.get(rId);
    if (null != existProp) {
        if (properties == null) {
            properties = Maps.newHashMap();
        }
        properties.putAll(existProp);
    }
    MxVertex vertex = new MxVertex(new Vertex(rId, type.getLabel(), properties, this.graph.getBaseGraph()), this.graph);
    if (vertexCacheFlag) {
        vertexCache.put(rId, vertex);
    }
    int count = vertexCountList.remove(rId);
    if (count > 1) {
        for (int i = 0; i < count; i++) {
            resultProcessor.process(vertex);
        }
    } else {
        resultProcessor.process(vertex);
    }
}
Also used : MxVertex(com.alibaba.maxgraph.structure.MxVertex) Vertex(com.alibaba.maxgraph.structure.Vertex) MxVertex(com.alibaba.maxgraph.structure.MxVertex) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) CompositeId(com.alibaba.maxgraph.sdkcommon.graph.CompositeId) GremlinQuery(com.alibaba.maxgraph.proto.GremlinQuery)

Example 3 with MxVertex

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

the class TinkerMaxGraph method vertices.

@Override
public Iterator<Vertex> vertices(Object... ids) {
    Iterator<com.alibaba.maxgraph.structure.Vertex> vertex;
    if (null == ids || ids.length == 0) {
        vertex = this.getBaseGraph().getVertex();
    } else {
        Set<ElementId> idSet = Sets.newHashSet();
        for (Object id : ids) {
            idSet.add(parseCompositeId(id));
        }
        if (idSet.isEmpty()) {
            List<Vertex> emptyList = Lists.newArrayList();
            return emptyList.iterator();
        }
        vertex = this.getBaseGraph().getVertex(idSet);
    }
    return Iterators.transform(vertex, v -> new MxVertex(v, this));
}
Also used : GraphVertex(com.alibaba.maxgraph.compiler.api.schema.GraphVertex) MxVertex(com.alibaba.maxgraph.structure.MxVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) MxVertex(com.alibaba.maxgraph.structure.MxVertex) ElementId(com.alibaba.maxgraph.sdkcommon.graph.ElementId)

Example 4 with MxVertex

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

the class MaxGraphRecordProcessorManager method addVertex.

public Vertex addVertex(AddVertexManager addVertexManager) {
    MxVertex mxVertex = new MxVertex(graph.getBaseGraph().addVertex(addVertexManager.label(), addVertexManager.getPropertyList()), this.graph);
    Vertex vertex = DetachedFactory.detach(mxVertex, true);
    vertexCache.put((ElementId) vertex.id(), vertex);
    return vertex;
}
Also used : MxVertex(com.alibaba.maxgraph.structure.MxVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) MxVertex(com.alibaba.maxgraph.structure.MxVertex)

Example 5 with MxVertex

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

Aggregations

MxVertex (com.alibaba.maxgraph.structure.MxVertex)5 ElementId (com.alibaba.maxgraph.sdkcommon.graph.ElementId)3 Vertex (com.alibaba.maxgraph.structure.Vertex)3 Map (java.util.Map)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)1 GraphVertex (com.alibaba.maxgraph.compiler.api.schema.GraphVertex)1 GremlinQuery (com.alibaba.maxgraph.proto.GremlinQuery)1 CompositeId (com.alibaba.maxgraph.sdkcommon.graph.CompositeId)1 Set (java.util.Set)1