Search in sources :

Example 1 with MapValueResult

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;
}
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 2 with MapValueResult

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());
                }
            }
        }
    }
}
Also used : PropertyValueResult(com.alibaba.maxgraph.result.PropertyValueResult) MapValueResult(com.alibaba.maxgraph.result.MapValueResult) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint)

Example 3 with 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;
}
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)

Example 4 with MapValueResult

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;
    }
}
Also used : GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) ElementId(com.alibaba.maxgraph.sdkcommon.graph.ElementId) RpcProcessorType(com.alibaba.maxgraph.server.query.RpcProcessorType) CacheFactory(com.alibaba.maxgraph.cache.CacheFactory) TinkerMaxGraph(com.alibaba.maxgraph.structure.graph.TinkerMaxGraph) CompositeId(com.alibaba.maxgraph.sdkcommon.graph.CompositeId) Graph(org.apache.tinkerpop.gremlin.structure.Graph) MxVertex(com.alibaba.maxgraph.structure.MxVertex) LoggerFactory(org.slf4j.LoggerFactory) Vertex(com.alibaba.maxgraph.structure.Vertex) PropertyResult(com.alibaba.maxgraph.result.PropertyResult) Lists(com.google.common.collect.Lists) RemoteRpcProcessor(com.alibaba.maxgraph.server.query.RemoteRpcProcessor) Map(java.util.Map) VertexResult(com.alibaba.maxgraph.result.VertexResult) ListResult(com.alibaba.maxgraph.result.ListResult) RemoteRpcConnector(com.alibaba.maxgraph.server.query.RemoteRpcConnector) Path(org.apache.tinkerpop.gremlin.process.traversal.Path) EdgeResult(com.alibaba.maxgraph.result.EdgeResult) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PathValueResult(com.alibaba.maxgraph.result.PathValueResult) PropertyValueResult(com.alibaba.maxgraph.result.PropertyValueResult) MapValueResult(com.alibaba.maxgraph.result.MapValueResult) Logger(org.slf4j.Logger) Set(java.util.Set) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) List(java.util.List) VertexPropertyResult(com.alibaba.maxgraph.result.VertexPropertyResult) QueryResult(com.alibaba.maxgraph.sdkcommon.graph.QueryResult) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) ResponseStatusCode(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode) Cache(com.google.common.cache.Cache) Context(org.apache.tinkerpop.gremlin.server.Context) DetachedFactory(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory) EntryValueResult(com.alibaba.maxgraph.sdkcommon.graph.EntryValueResult) MutablePath(org.apache.tinkerpop.gremlin.process.traversal.step.util.MutablePath) MxVertex(com.alibaba.maxgraph.structure.MxVertex) Vertex(com.alibaba.maxgraph.structure.Vertex) Set(java.util.Set) CompositeId(com.alibaba.maxgraph.sdkcommon.graph.CompositeId) PropertyResult(com.alibaba.maxgraph.result.PropertyResult) VertexPropertyResult(com.alibaba.maxgraph.result.VertexPropertyResult) VertexResult(com.alibaba.maxgraph.result.VertexResult) MapValueResult(com.alibaba.maxgraph.result.MapValueResult) List(java.util.List) EntryValueResult(com.alibaba.maxgraph.sdkcommon.graph.EntryValueResult) ElementId(com.alibaba.maxgraph.sdkcommon.graph.ElementId) VertexPropertyResult(com.alibaba.maxgraph.result.VertexPropertyResult) Path(org.apache.tinkerpop.gremlin.process.traversal.Path) MutablePath(org.apache.tinkerpop.gremlin.process.traversal.step.util.MutablePath) PropertyValueResult(com.alibaba.maxgraph.result.PropertyValueResult) ListResult(com.alibaba.maxgraph.result.ListResult) PathValueResult(com.alibaba.maxgraph.result.PathValueResult) Map(java.util.Map) EdgeResult(com.alibaba.maxgraph.result.EdgeResult)

Aggregations

MapValueResult (com.alibaba.maxgraph.result.MapValueResult)4 PropertyValueResult (com.alibaba.maxgraph.result.PropertyValueResult)4 QueryResult (com.alibaba.maxgraph.sdkcommon.graph.QueryResult)3 ListResult (com.alibaba.maxgraph.result.ListResult)2 List (java.util.List)2 Map (java.util.Map)2 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)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 PathValueResult (com.alibaba.maxgraph.result.PathValueResult)1 PropertyResult (com.alibaba.maxgraph.result.PropertyResult)1 VertexPropertyResult (com.alibaba.maxgraph.result.VertexPropertyResult)1 VertexResult (com.alibaba.maxgraph.result.VertexResult)1 Endpoint (com.alibaba.maxgraph.sdkcommon.client.Endpoint)1 CompositeId (com.alibaba.maxgraph.sdkcommon.graph.CompositeId)1 ElementId (com.alibaba.maxgraph.sdkcommon.graph.ElementId)1 EntryValueResult (com.alibaba.maxgraph.sdkcommon.graph.EntryValueResult)1