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");
}
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);
}
}
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));
}
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));
}
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));
}
Aggregations