use of com.alibaba.maxgraph.sdkcommon.graph.EntryValueResult in project GraphScope by alibaba.
the class ResultParserUtils method parseEntry.
private static QueryResult parseEntry(Message.RawMessageProto message, GraphSchema schema, Graph graph) {
try {
Message.EntryProto entry = Message.EntryProto.parseFrom(message.getExtra().getExtraValueProp().getValueEntity().getPayload());
EntryValueResult entryValueResult = new EntryValueResult();
entryValueResult.setKey(parseRawMessage(entry.getKey(), schema, graph));
entryValueResult.setValue(parseRawMessage(entry.getValue(), schema, graph));
return entryValueResult;
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
}
use of com.alibaba.maxgraph.sdkcommon.graph.EntryValueResult 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