Search in sources :

Example 1 with Vertex

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

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

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

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

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

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