use of com.alibaba.maxgraph.result.VertexResult in project GraphScope by alibaba.
the class GremlinResultTransform method transform.
public void transform(List<QueryResult> resultObjectList, GraphSchema schema, Map<Integer, String> labelIndexNameList, Context context, int batchSize, List<Object> resultList, String queryId) {
Map<ElementId, Integer> vertexCountList = Maps.newHashMap();
List<CompositeId> resultVertexIdList = Lists.newArrayListWithCapacity(resultObjectList.size());
Map<CompositeId, org.apache.tinkerpop.gremlin.structure.Vertex> idToVertexList = Maps.newHashMap();
Map<CompositeId, Map<String, Object>> existPropMap = Maps.newHashMap();
Map<Integer, Set<ElementId>> storeVertexList = Maps.newHashMap();
for (int i = 0; i < resultObjectList.size(); i++) {
QueryResult queryResult = resultObjectList.get(i);
if (queryResult instanceof VertexResult) {
VertexResult vertexResult = VertexResult.class.cast(queryResult);
CompositeId compositeId = new CompositeId(vertexResult.id, schema.getElement(vertexResult.label).getLabelId());
org.apache.tinkerpop.gremlin.structure.Vertex cachedVertex = vertexCache.getIfPresent(compositeId);
if (null != cachedVertex) {
resultVertexIdList.add(compositeId);
idToVertexList.put(compositeId, cachedVertex);
} else {
resultVertexIdList.add(compositeId);
vertexCountList.compute(compositeId, (key, oldValue) -> {
if (null == oldValue) {
return 1;
} else {
return oldValue + 1;
}
});
Set<ElementId> storeVertices = storeVertexList.computeIfAbsent(vertexResult.getStoreId(), k -> Sets.newHashSet());
storeVertices.add(compositeId);
extractExistProp(existPropMap, vertexResult, compositeId);
}
} else {
Object result = parseResultValue(queryResult, schema, this.graph, labelIndexNameList, context, batchSize, queryId);
if (null != resultList) {
resultList.add(result);
}
remoteRpcProcessor.process(result);
}
}
if (!vertexCountList.isEmpty()) {
List<Object> currResultList = Lists.newArrayListWithCapacity(vertexCountList.size());
queryVertices(schema, context, batchSize, currResultList, vertexCountList, storeVertexList, existPropMap, RpcProcessorType.MEMORY, queryId);
for (Object currResult : currResultList) {
org.apache.tinkerpop.gremlin.structure.Vertex currVertex = org.apache.tinkerpop.gremlin.structure.Vertex.class.cast(currResult);
CompositeId vertexId = CompositeId.class.cast(currVertex.id());
idToVertexList.put(vertexId, currVertex);
}
}
if (!resultVertexIdList.isEmpty()) {
for (CompositeId compositeId : resultVertexIdList) {
org.apache.tinkerpop.gremlin.structure.Vertex resultVertex = idToVertexList.get(compositeId);
remoteRpcProcessor.process(resultVertex);
if (null != resultList) {
resultList.add(resultVertex);
}
}
}
}
use of com.alibaba.maxgraph.result.VertexResult in project GraphScope by alibaba.
the class ResultParserUtils method parseProperty.
private static QueryResult parseProperty(Message.RawMessageProto message, GraphSchema schema, Graph graph) {
String propName = getPropertyName((int) message.getId(), schema);
Object propValue = parseValue(message.getExtra().getExtraValueProp().getValueEntity(), schema, graph);
if (message.getTypeId() == 0) {
return new VertexPropertyResult<>((int) message.getId(), propName, propValue, new VertexResult(0, 0, "", graph, 0));
} else {
return new PropertyResult<>(propName, propValue, new VertexResult(0, 0, "", graph, 0));
}
}
use of com.alibaba.maxgraph.result.VertexResult in project GraphScope by alibaba.
the class ResultParserUtils method parseVertex.
private static VertexResult parseVertex(Message.RawMessageProto message, GraphSchema schema, Graph graph) {
long id = message.getId();
int typeId = message.getTypeId();
int storeId = message.getStoreId();
VertexResult v = parseVertex(id, typeId, schema, graph, storeId);
for (PropertyEntityProto p : message.getExtra().getExtraValueProp().getPropListList()) {
Object value = parseValue(p.getPropValue(), schema, graph);
String name = getPropertyName(p.getPropId(), schema);
v.addProperty(new VertexPropertyResult(p.getPropId(), name, value, null));
}
return v;
}
use of com.alibaba.maxgraph.result.VertexResult in project GraphScope by alibaba.
the class GremlinResultTransform method parseResultValue.
private Object parseResultValue(QueryResult queryResult, GraphSchema schema, Graph graph, Map<Integer, String> labelIndexNameList, Context context, int batchSize, String queryId) {
if (queryResult instanceof VertexPropertyResult || queryResult instanceof PropertyResult) {
return queryResult;
} else if (queryResult instanceof MapValueResult) {
Map<Object, Object> resultMap = Maps.newLinkedHashMap();
for (Map.Entry<QueryResult, QueryResult> entry : ((MapValueResult) queryResult).getValueMap().entrySet()) {
resultMap.put(parseResultValue(entry.getKey(), schema, graph, labelIndexNameList, context, batchSize, queryId), parseResultValue(entry.getValue(), schema, graph, labelIndexNameList, context, batchSize, queryId));
}
return resultMap;
} else if (queryResult instanceof EdgeResult) {
return DetachedFactory.detach((Edge) queryResult, true);
} else if (queryResult instanceof ListResult) {
List<QueryResult> resultList = ((ListResult) queryResult).getResultList();
if (resultList.isEmpty()) {
return Lists.newArrayList();
}
if (resultList.get(0) instanceof PathValueResult) {
Path path = MutablePath.make();
resultList.forEach(v -> {
PathValueResult pathValueResult = PathValueResult.class.cast(v);
Set<String> labelNameList = Sets.newHashSet();
pathValueResult.getLabelIdList().forEach(labelId -> labelNameList.add(labelIndexNameList.get(labelId)));
path.extend(parseResultValue(pathValueResult.getValue(), schema, graph, labelIndexNameList, context, batchSize, queryId), labelNameList);
});
return DetachedFactory.detach(path, true);
} else {
List<Object> listValue = Lists.newArrayList();
resultList.forEach(v -> listValue.add(parseResultValue(v, schema, graph, labelIndexNameList, context, batchSize, queryId)));
return listValue;
}
} else if (queryResult instanceof EntryValueResult) {
Map<Object, Object> mapValue = Maps.newHashMap();
mapValue.put(parseResultValue(((EntryValueResult) queryResult).getKey(), schema, graph, labelIndexNameList, context, batchSize, queryId), parseResultValue(((EntryValueResult) queryResult).getValue(), schema, graph, labelIndexNameList, context, batchSize, queryId));
return mapValue.entrySet().iterator().next();
} else if (queryResult instanceof PropertyValueResult) {
return ((PropertyValueResult) queryResult).getValue();
} else if (queryResult instanceof VertexResult) {
VertexResult vertexResult = (VertexResult) queryResult;
CompositeId compositeId = CompositeId.class.cast(vertexResult.id());
org.apache.tinkerpop.gremlin.structure.Vertex cachedVertex = vertexCache.getIfPresent(compositeId);
if (null == cachedVertex) {
List<Object> resultList = Lists.newArrayList();
Map<ElementId, Integer> elementIdIntegerMap = Maps.newHashMap();
elementIdIntegerMap.put(compositeId, 1);
Map<CompositeId, Map<String, Object>> existPropMap = Maps.newHashMap();
extractExistProp(existPropMap, vertexResult, compositeId);
Map<Integer, Set<ElementId>> storeVertexList = Maps.newHashMap();
storeVertexList.put(vertexResult.getStoreId(), Sets.newHashSet(compositeId));
queryVertices(schema, context, batchSize, resultList, elementIdIntegerMap, storeVertexList, existPropMap, RpcProcessorType.MEMORY, queryId);
cachedVertex = org.apache.tinkerpop.gremlin.structure.Vertex.class.cast(resultList.get(0));
}
return cachedVertex;
} else {
return queryResult;
}
}
Aggregations