use of com.alibaba.maxgraph.result.BulkResult 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;
}
Aggregations