use of com.alibaba.maxgraph.sdkcommon.graph.QueryResult 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.sdkcommon.graph.QueryResult 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.sdkcommon.graph.QueryResult in project GraphScope by alibaba.
the class RpcConnector method showProcessList.
public void showProcessList(TimelyResultProcessor resultProcessor) throws Exception {
MaxGraphCtrlServiceBlockingStub stub = randomCtrlStub(getTargetExecutorAddrs().get(0));
ShowProcessListResponse resp = stub.showProcessList(ShowProcessListRequest.newBuilder().build());
List<QueryResult> processNameList = Lists.newArrayList();
for (RunningQuery runningQuery : resp.getQueriesList()) {
processNameList.add(new PropertyValueResult(runningQuery.getQueryId() + "[" + runningQuery.getScript() + "][" + runningQuery.getElapsedNano() / 1000000 + "ms]"));
}
ListResult listResult = new ListResult(processNameList);
resultProcessor.process(listResult);
resultProcessor.finish();
}
use of com.alibaba.maxgraph.sdkcommon.graph.QueryResult in project GraphScope by alibaba.
the class BigGraphResultProcessor method getResultVertexList.
public static List<String> getResultVertexList(List<QueryResult> queryResultList) {
List<String> resultList = Lists.newArrayList();
for (QueryResult result : queryResultList) {
resultList.add(String.valueOf(VertexResult.class.cast(result).id));
}
Collections.sort(resultList);
return resultList;
}
use of com.alibaba.maxgraph.sdkcommon.graph.QueryResult 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;
}
Aggregations