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