Search in sources :

Example 1 with QueryResult

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);
            }
        }
    }
}
Also used : MxVertex(com.alibaba.maxgraph.structure.MxVertex) Vertex(com.alibaba.maxgraph.structure.Vertex) Set(java.util.Set) CompositeId(com.alibaba.maxgraph.sdkcommon.graph.CompositeId) QueryResult(com.alibaba.maxgraph.sdkcommon.graph.QueryResult) VertexResult(com.alibaba.maxgraph.result.VertexResult) Map(java.util.Map) ElementId(com.alibaba.maxgraph.sdkcommon.graph.ElementId)

Example 2 with QueryResult

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;
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) PropertyValueResult(com.alibaba.maxgraph.result.PropertyValueResult) ByteString(com.google.protobuf.ByteString) BulkResult(com.alibaba.maxgraph.result.BulkResult) ListResult(com.alibaba.maxgraph.result.ListResult) QueryResult(com.alibaba.maxgraph.sdkcommon.graph.QueryResult) MapValueResult(com.alibaba.maxgraph.result.MapValueResult) List(java.util.List)

Example 3 with 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();
}
Also used : ListResult(com.alibaba.maxgraph.result.ListResult) QueryResult(com.alibaba.maxgraph.sdkcommon.graph.QueryResult) MaxGraphCtrlServiceBlockingStub(com.alibaba.maxgraph.rpc.MaxGraphCtrlServiceGrpc.MaxGraphCtrlServiceBlockingStub) PropertyValueResult(com.alibaba.maxgraph.result.PropertyValueResult)

Example 4 with QueryResult

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;
}
Also used : QueryResult(com.alibaba.maxgraph.sdkcommon.graph.QueryResult) VertexResult(com.alibaba.maxgraph.result.VertexResult)

Example 5 with QueryResult

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;
}
Also used : QueryResult(com.alibaba.maxgraph.sdkcommon.graph.QueryResult) MapValueResult(com.alibaba.maxgraph.result.MapValueResult) PropertyValueResult(com.alibaba.maxgraph.result.PropertyValueResult) Map(java.util.Map)

Aggregations

QueryResult (com.alibaba.maxgraph.sdkcommon.graph.QueryResult)7 PropertyValueResult (com.alibaba.maxgraph.result.PropertyValueResult)4 ListResult (com.alibaba.maxgraph.result.ListResult)3 MapValueResult (com.alibaba.maxgraph.result.MapValueResult)3 VertexResult (com.alibaba.maxgraph.result.VertexResult)3 Map (java.util.Map)3 PathValueResult (com.alibaba.maxgraph.result.PathValueResult)2 CompositeId (com.alibaba.maxgraph.sdkcommon.graph.CompositeId)2 ElementId (com.alibaba.maxgraph.sdkcommon.graph.ElementId)2 MxVertex (com.alibaba.maxgraph.structure.MxVertex)2 Vertex (com.alibaba.maxgraph.structure.Vertex)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 List (java.util.List)2 Set (java.util.Set)2 Message (com.alibaba.maxgraph.Message)1 CacheFactory (com.alibaba.maxgraph.cache.CacheFactory)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 ValueType (com.alibaba.maxgraph.compiler.tree.value.ValueType)1 BulkResult (com.alibaba.maxgraph.result.BulkResult)1 EdgeResult (com.alibaba.maxgraph.result.EdgeResult)1