Search in sources :

Example 6 with GraphElement

use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.

the class GraphWriter method addOverwriteVertexOperation.

private void addOverwriteVertexOperation(OperationBatch.Builder batchBuilder, GraphSchema schema, DataRecord dataRecord) {
    VertexRecordKey vertexRecordKey = dataRecord.getVertexRecordKey();
    Map<String, Object> properties = dataRecord.getProperties();
    String label = vertexRecordKey.getLabel();
    GraphElement vertexDef = schema.getElement(label);
    int labelId = vertexDef.getLabelId();
    Map<Integer, PropertyValue> pkVals = parseRawProperties(vertexDef, vertexRecordKey.getProperties());
    Map<Integer, PropertyValue> propertyVals = parseRawProperties(vertexDef, properties);
    propertyVals.putAll(pkVals);
    long hashId = getHashId(labelId, propertyVals, vertexDef);
    batchBuilder.addOperation(new OverwriteVertexOperation(new VertexId(hashId), new LabelId(labelId), propertyVals));
}
Also used : PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) VertexId(com.alibaba.graphscope.groot.operation.VertexId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Example 7 with GraphElement

use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.

the class VertexStreamObserver method onNext.

@Override
public void onNext(GremlinQuery.VertexResponse vertexResponse) {
    GremlinQuery.VertexId id = vertexResponse.getId();
    CompositeId rId = new CompositeId(id.getId(), id.getTypeId());
    GraphElement type = schema.getElement(id.getTypeId());
    Map<String, Object> properties = null;
    try {
        properties = RpcProcessorUtils.deserializeProperty(vertexResponse.getPros().toByteArray(), type, schema);
    } catch (Exception e) {
        throw new RuntimeException("query properties for vertex=>" + rId.toString() + " fail", e);
    }
    Map<String, Object> existProp = existPropMap.get(rId);
    if (null != existProp) {
        if (properties == null) {
            properties = Maps.newHashMap();
        }
        properties.putAll(existProp);
    }
    MxVertex vertex = new MxVertex(new Vertex(rId, type.getLabel(), properties, this.graph.getBaseGraph()), this.graph);
    if (vertexCacheFlag) {
        vertexCache.put(rId, vertex);
    }
    int count = vertexCountList.remove(rId);
    if (count > 1) {
        for (int i = 0; i < count; i++) {
            resultProcessor.process(vertex);
        }
    } else {
        resultProcessor.process(vertex);
    }
}
Also used : MxVertex(com.alibaba.maxgraph.structure.MxVertex) Vertex(com.alibaba.maxgraph.structure.Vertex) MxVertex(com.alibaba.maxgraph.structure.MxVertex) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) CompositeId(com.alibaba.maxgraph.sdkcommon.graph.CompositeId) GremlinQuery(com.alibaba.maxgraph.proto.GremlinQuery)

Example 8 with GraphElement

use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.

the class DefaultGraphSchema method getPropertyList.

@Override
public Map<GraphElement, GraphProperty> getPropertyList(String propName) {
    Map<GraphElement, GraphProperty> elementPropertyList = Maps.newHashMap();
    vertexList.forEach((key, value) -> {
        for (GraphProperty property : value.getPropertyList()) {
            if (StringUtils.equals(property.getName(), propName)) {
                elementPropertyList.put(value, property);
            }
        }
    });
    edgeList.forEach((key, value) -> {
        for (GraphProperty property : value.getPropertyList()) {
            if (StringUtils.equals(property.getName(), propName)) {
                elementPropertyList.put(value, property);
            }
        }
    });
    return elementPropertyList;
}
Also used : GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement)

Example 9 with GraphElement

use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.

the class TinkerMaxGraph method parseVertexProperties.

private Pair<String, Map<String, Object>> parseVertexProperties(Object... keyValues) {
    Map<String, Object> kvs = Utils.convertToMap(keyValues);
    Object labelObj = kvs.remove(T.label.toString());
    if (labelObj == null) {
        labelObj = Vertex.DEFAULT_LABEL;
    }
    final String label = labelObj.toString();
    GraphSchema schema = graph.getSchema();
    GraphElement graphElement = schema.getElement(label);
    if (!(graphElement instanceof GraphVertex)) {
        throw new IllegalArgumentException("Label " + label + " is not vertex");
    }
    List<GraphProperty> primaryKeyList = ((GraphVertex) graphElement).getPrimaryKeyList();
    if (kvs.isEmpty()) {
        for (GraphProperty property : primaryKeyList) {
            kvs.put(property.getName(), property.getDataType().getRandomValue());
        }
    } else {
        for (GraphProperty property : primaryKeyList) {
            if (!kvs.containsKey(property.getName())) {
                kvs.put(property.getName(), property.getDataType().getRandomValue());
            }
        }
    }
    return Pair.of(label, kvs);
}
Also used : GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) GraphVertex(com.alibaba.maxgraph.compiler.api.schema.GraphVertex) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema)

Example 10 with GraphElement

use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.

the class RemoteProxy method getOutEdges.

public Iterator<Edge> getOutEdges(Set<Vertex> v, String... label) {
    List<Iterator<StoreApi.GraphEdgeReponse>> iterEdgeList = Lists.newArrayList();
    Pair<GraphSchema, Long> schemaPair = schemaFetcher.getSchemaSnapshotPair();
    GraphSchema schema = schemaPair.getLeft();
    long snapshotId = schemaPair.getRight();
    for (Vertex vertex : v) {
        if (label.length == 0) {
            StoreApi.GetOutEdgesRequest.Builder req = StoreApi.GetOutEdgesRequest.newBuilder();
            req.setSnapshotId(snapshotId).setSrcId(vertex.id.id()).setSnapshotId(schemaPair.getRight());
            Iterator<StoreApi.GraphEdgeReponse> edgeResponse = stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).getOutEdges(req.build());
            iterEdgeList.add(edgeResponse);
        } else {
            for (String labelVal : label) {
                try {
                    GraphElement element = schema.getElement(labelVal);
                    int labelId = element.getLabelId();
                    StoreApi.GetOutEdgesRequest.Builder req = StoreApi.GetOutEdgesRequest.newBuilder();
                    req.setSnapshotId(snapshotId).setSrcId(vertex.id.id()).setTypeId(labelId).setSnapshotId(schemaPair.getRight());
                    Iterator<StoreApi.GraphEdgeReponse> edgeResponse = stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).getOutEdges(req.build());
                    iterEdgeList.add(edgeResponse);
                } catch (Exception ignored) {
                }
            }
        }
    }
    return new IteratorList<>(iterEdgeList, new EdgeResponseFunction(schema, this.graph));
}
Also used : Vertex(com.alibaba.maxgraph.structure.Vertex) EdgeResponseFunction(com.alibaba.maxgraph.iterator.function.EdgeResponseFunction) StoreApi(com.alibaba.maxgraph.proto.StoreApi) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) IteratorList(com.alibaba.maxgraph.iterator.IteratorList)

Aggregations

GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)18 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)7 VertexId (com.alibaba.graphscope.groot.operation.VertexId)6 VertexRecordKey (com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey)6 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)6 PropertyValue (com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Vertex (com.alibaba.maxgraph.structure.Vertex)5 EdgeId (com.alibaba.graphscope.groot.operation.EdgeId)3 GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)3 GremlinQuery (com.alibaba.maxgraph.proto.GremlinQuery)3 EdgeRecordKey (com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey)3 CompositeId (com.alibaba.maxgraph.sdkcommon.graph.CompositeId)3 EdgeKind (com.alibaba.maxgraph.sdkcommon.schema.EdgeKind)3 Map (java.util.Map)3 MaxGraphClient (com.alibaba.graphscope.groot.sdk.MaxGraphClient)2 EdgeRelation (com.alibaba.maxgraph.compiler.api.schema.EdgeRelation)2 GraphProperty (com.alibaba.maxgraph.compiler.api.schema.GraphProperty)2 EdgeOtherVertexTreeNode (com.alibaba.maxgraph.compiler.tree.EdgeOtherVertexTreeNode)2 EdgeTreeNode (com.alibaba.maxgraph.compiler.tree.EdgeTreeNode)2