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