use of com.alibaba.maxgraph.result.MapValueResult in project GraphScope by alibaba.
the class ResultParserUtils method parseRawMessage.
public static QueryResult parseRawMessage(Message.RawMessageProto message, GraphSchema schema, Graph graph) {
QueryResult queryResult = null;
long bulkValue = message.getBulk() > 0 ? message.getBulk() : 1;
switch(message.getMessageType()) {
case MSG_VERTEX_TYPE:
{
queryResult = parseVertex(message, schema, graph);
break;
}
case MSG_EDGE_TYPE:
{
queryResult = parseEdge(message, schema, graph);
break;
}
case MSG_PROP_TYPE:
{
queryResult = parseProperty(message, schema, graph);
break;
}
case MSG_VALUE_TYPE:
{
Object value = parseValue(message.getExtra().getExtraValueProp().getValueEntity(), schema, graph);
if (value instanceof QueryResult) {
queryResult = (QueryResult) value;
} else {
queryResult = new PropertyValueResult(value);
}
break;
}
case MSG_ENTRY_TYPE:
{
queryResult = parseEntry(message, schema, graph);
break;
}
case MSG_PATH_ENTRY_TYPE:
{
queryResult = parsePathEntry(message, schema, graph);
break;
}
case MSG_LIST_TYPE:
{
try {
Message.ListProto listProto = Message.ListProto.parseFrom(message.getExtra().getExtraValueProp().getValueEntity().getPayload());
List<QueryResult> resultList = Lists.newArrayList();
for (Message.RawMessageProto listEntry : listProto.getValueList()) {
QueryResult result = parseRawMessage(listEntry, schema, graph);
if (result instanceof BulkResult) {
resultList.addAll(((BulkResult) result).getResultList());
} else {
resultList.add(result);
}
}
queryResult = new ListResult(resultList);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
break;
}
case MSG_MAP_TYPE:
{
try {
Message.MapProto mapProto = Message.MapProto.parseFrom(message.getExtra().getExtraValueProp().getValueEntity().getPayload());
MapValueResult mapList = new MapValueResult();
for (Message.EntryProto mapEntry : mapProto.getEntryListList()) {
mapList.addMapValue(parseRawMessage(mapEntry.getKey(), schema, graph), parseRawMessage(mapEntry.getValue(), schema, graph));
}
queryResult = mapList;
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
break;
}
case MSG_ERROR_TYPE:
{
String errorMessage = new String(message.getExtra().getExtraValueProp().getValueEntity().getPayload().toByteArray());
throw new RuntimeException(errorMessage);
}
case MSG_DFS_CMD_TYPE:
case UNRECOGNIZED:
{
throw new RuntimeException(message.getMessageType().toString());
}
}
if (queryResult != null && bulkValue > 1) {
return new BulkResult(Collections.nCopies((int) bulkValue, queryResult));
}
return queryResult;
}
use of com.alibaba.maxgraph.result.MapValueResult in project GraphScope by alibaba.
the class RpcConnector method processEmptyResult.
private void processEmptyResult(TimelyResultProcessor resultProcessor, QueryFlowOuterClass.QueryFlow queryFlowPlan) {
long totalCount = resultProcessor.total();
List<Integer> operatorIpdList = queryFlowPlan.getQueryPlan().getOperatorIdListList();
int lastOperatorId = operatorIpdList.get(operatorIpdList.size() - 1);
if (totalCount == 0) {
for (QueryFlowOuterClass.UnaryOperator unaryOperator : queryFlowPlan.getQueryPlan().getUnaryOpList()) {
if (unaryOperator.getBase().getId() == lastOperatorId) {
if (unaryOperator.getBase().getOperatorType() == QueryFlowOuterClass.OperatorType.COUNT) {
resultProcessor.process(new PropertyValueResult(0L));
} else if (unaryOperator.getBase().getOperatorType() == QueryFlowOuterClass.OperatorType.GROUP_COUNT || unaryOperator.getBase().getOperatorType() == QueryFlowOuterClass.OperatorType.FOLDMAP) {
resultProcessor.process(new MapValueResult());
}
}
}
}
}
use of com.alibaba.maxgraph.result.MapValueResult in project GraphScope by alibaba.
the class BigGraphResultProcessor method getResultMapList.
public static List<Map<String, String>> getResultMapList(List<QueryResult> resultList) {
List<Map<String, String>> mapValueList = Lists.newArrayList();
for (QueryResult result : resultList) {
MapValueResult mapValueResult = MapValueResult.class.cast(result);
Map<QueryResult, QueryResult> mapValue = mapValueResult.getValueMap();
Map<String, String> resultMapValue = Maps.newHashMap();
for (Map.Entry<QueryResult, QueryResult> entry : mapValue.entrySet()) {
resultMapValue.put(PropertyValueResult.class.cast(entry.getKey()).getValue().toString(), PropertyValueResult.class.cast(entry.getValue()).getValue().toString());
}
mapValueList.add(resultMapValue);
}
return mapValueList;
}
use of com.alibaba.maxgraph.result.MapValueResult 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