Search in sources :

Example 1 with EdgeKindPb

use of com.alibaba.maxgraph.proto.groot.EdgeKindPb in project GraphScope by alibaba.

the class AddEdgeKindExecutor method execute.

@Override
public DdlResult execute(ByteString ddlBlob, GraphDef graphDef, int partitionCount) throws InvalidProtocolBufferException {
    EdgeKindPb edgeKindPb = EdgeKindPb.parseFrom(ddlBlob);
    EdgeKind edgeKind = EdgeKind.parseProto(edgeKindPb);
    long version = graphDef.getSchemaVersion();
    EdgeKind.Builder edgeKindBuilder = EdgeKind.newBuilder(edgeKind);
    String edgeLabel = edgeKind.getEdgeLabel();
    LabelId edgeLabelId = graphDef.getLabelId(edgeLabel);
    if (edgeLabelId == null) {
        throw new DdlException("invalid edgeLabel [" + edgeLabel + "], schema version [" + version + "]");
    }
    edgeKindBuilder.setEdgeLabelId(edgeLabelId);
    String srcVertexLabel = edgeKind.getSrcVertexLabel();
    LabelId srcVertexLabelId = graphDef.getLabelId(srcVertexLabel);
    if (srcVertexLabelId == null) {
        throw new DdlException("invalid srcVertexLabel [" + srcVertexLabel + "], schema version [" + version + "]");
    }
    edgeKindBuilder.setSrcVertexLabelId(srcVertexLabelId);
    String dstVertexLabel = edgeKind.getDstVertexLabel();
    LabelId dstVertexLabelId = graphDef.getLabelId(dstVertexLabel);
    if (dstVertexLabelId == null) {
        throw new DdlException("invalid dstVertexLabel [" + dstVertexLabel + "], schema version [" + version + "]");
    }
    edgeKindBuilder.setDstVertexLabelId(dstVertexLabelId);
    EdgeKind newEdgeKind = edgeKindBuilder.build();
    if (graphDef.hasEdgeKind(newEdgeKind)) {
        throw new DdlException("edgeKind [" + newEdgeKind + "] already exists, schema version [" + version + "]");
    }
    GraphDef.Builder graphDefBuilder = GraphDef.newBuilder(graphDef);
    version++;
    graphDefBuilder.setVersion(version);
    graphDefBuilder.addEdgeKind(newEdgeKind);
    long tableIdx = graphDef.getTableIdx();
    tableIdx++;
    graphDefBuilder.putEdgeTableId(newEdgeKind, tableIdx);
    graphDefBuilder.setTableIdx(tableIdx);
    GraphDef newGraphDef = graphDefBuilder.build();
    List<Operation> operations = new ArrayList<>(partitionCount);
    for (int i = 0; i < partitionCount; i++) {
        operations.add(new AddEdgeKindOperation(i, version, newEdgeKind, tableIdx));
    }
    return new DdlResult(newGraphDef, operations);
}
Also used : DdlException(com.alibaba.graphscope.groot.schema.request.DdlException) EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) EdgeKindPb(com.alibaba.maxgraph.proto.groot.EdgeKindPb) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Operation(com.alibaba.graphscope.groot.operation.Operation) AddEdgeKindOperation(com.alibaba.graphscope.groot.operation.ddl.AddEdgeKindOperation) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) AddEdgeKindOperation(com.alibaba.graphscope.groot.operation.ddl.AddEdgeKindOperation) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Example 2 with EdgeKindPb

use of com.alibaba.maxgraph.proto.groot.EdgeKindPb in project GraphScope by alibaba.

the class RemoveEdgeKindExecutor method execute.

@Override
public DdlResult execute(ByteString ddlBlob, GraphDef graphDef, int partitionCount) throws InvalidProtocolBufferException {
    EdgeKindPb edgeKindPb = EdgeKindPb.parseFrom(ddlBlob);
    EdgeKind edgeKind = EdgeKind.parseProto(edgeKindPb);
    long version = graphDef.getSchemaVersion();
    EdgeKind.Builder edgeKindBuilder = EdgeKind.newBuilder(edgeKind);
    String edgeLabel = edgeKind.getEdgeLabel();
    LabelId edgeLabelId = graphDef.getLabelId(edgeLabel);
    if (edgeLabelId == null) {
        throw new DdlException("invalid edgeLabel [" + edgeLabel + "], schema version [" + version + "]");
    }
    edgeKindBuilder.setEdgeLabelId(edgeLabelId);
    String srcVertexLabel = edgeKind.getSrcVertexLabel();
    LabelId srcVertexLabelId = graphDef.getLabelId(srcVertexLabel);
    if (srcVertexLabelId == null) {
        throw new DdlException("invalid srcVertexLabel [" + srcVertexLabel + "], schema version [" + version + "]");
    }
    edgeKindBuilder.setSrcVertexLabelId(srcVertexLabelId);
    String dstVertexLabel = edgeKind.getDstVertexLabel();
    LabelId dstVertexLabelId = graphDef.getLabelId(dstVertexLabel);
    if (dstVertexLabelId == null) {
        throw new DdlException("invalid dstVertexLabel [" + dstVertexLabel + "], schema version [" + version + "]");
    }
    edgeKindBuilder.setDstVertexLabelId(dstVertexLabelId);
    EdgeKind edgeKindToRemove = edgeKindBuilder.build();
    if (!graphDef.hasEdgeKind(edgeKindToRemove)) {
        throw new DdlException("edgeKind [" + edgeKind + "] not exists, schema version [" + version + "]");
    }
    GraphDef.Builder graphDefBuilder = GraphDef.newBuilder(graphDef);
    version++;
    graphDefBuilder.setVersion(version);
    graphDefBuilder.removeEdgeKind(edgeKindToRemove);
    GraphDef newGraphDef = graphDefBuilder.build();
    List<Operation> operations = new ArrayList<>(partitionCount);
    for (int i = 0; i < partitionCount; i++) {
        operations.add(new RemoveEdgeKindOperation(i, version, edgeKindToRemove));
    }
    return new DdlResult(newGraphDef, operations);
}
Also used : DdlException(com.alibaba.graphscope.groot.schema.request.DdlException) RemoveEdgeKindOperation(com.alibaba.graphscope.groot.operation.ddl.RemoveEdgeKindOperation) EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) EdgeKindPb(com.alibaba.maxgraph.proto.groot.EdgeKindPb) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) RemoveEdgeKindOperation(com.alibaba.graphscope.groot.operation.ddl.RemoveEdgeKindOperation) Operation(com.alibaba.graphscope.groot.operation.Operation) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Example 3 with EdgeKindPb

use of com.alibaba.maxgraph.proto.groot.EdgeKindPb in project GraphScope by alibaba.

the class GraphDef method parseProto.

public static GraphDef parseProto(GraphDefPb proto) {
    long version = proto.getVersion();
    Map<String, LabelId> labelToId = new HashMap<>();
    Map<LabelId, TypeDef> idToType = new HashMap<>();
    for (TypeDefPb typeDefPb : proto.getTypeDefsList()) {
        TypeDef typeDef = TypeDef.parseProto(typeDefPb);
        LabelId labelId = typeDef.getTypeLabelId();
        labelToId.put(typeDef.getLabel(), labelId);
        idToType.put(labelId, typeDef);
    }
    Map<LabelId, Set<EdgeKind>> idToKinds = new HashMap<>();
    for (EdgeKindPb edgeKindPb : proto.getEdgeKindsList()) {
        EdgeKind edgeKind = EdgeKind.parseProto(edgeKindPb);
        Set<EdgeKind> edgeKindSet = idToKinds.computeIfAbsent(edgeKind.getEdgeLabelId(), k -> new HashSet<>());
        edgeKindSet.add(edgeKind);
    }
    Map<String, Integer> propertyNameToId = proto.getPropertyNameToIdMap();
    int labelIdx = proto.getLabelIdx();
    int propertyIdx = proto.getPropertyIdx();
    Map<LabelId, Long> vertexTableIds = new HashMap<>();
    for (VertexTableIdEntry vertexTableIdEntry : proto.getVertexTableIdsList()) {
        vertexTableIds.put(LabelId.parseProto(vertexTableIdEntry.getLabelId()), vertexTableIdEntry.getTableId());
    }
    Map<EdgeKind, Long> edgeTableIds = new HashMap<>();
    for (EdgeTableIdEntry edgeTableIdEntry : proto.getEdgeTableIdsList()) {
        edgeTableIds.put(EdgeKind.parseProto(edgeTableIdEntry.getEdgeKind()), edgeTableIdEntry.getTableId());
    }
    long tableIdx = proto.getTableIdx();
    return new GraphDef(version, labelToId, idToType, idToKinds, propertyNameToId, labelIdx, propertyIdx, vertexTableIds, edgeTableIds, tableIdx);
}
Also used : EdgeTableIdEntry(com.alibaba.maxgraph.proto.groot.EdgeTableIdEntry) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) EdgeKindPb(com.alibaba.maxgraph.proto.groot.EdgeKindPb) VertexTableIdEntry(com.alibaba.maxgraph.proto.groot.VertexTableIdEntry) TypeDefPb(com.alibaba.maxgraph.proto.groot.TypeDefPb)

Aggregations

EdgeKindPb (com.alibaba.maxgraph.proto.groot.EdgeKindPb)3 Operation (com.alibaba.graphscope.groot.operation.Operation)2 DdlException (com.alibaba.graphscope.groot.schema.request.DdlException)2 EdgeKind (com.alibaba.maxgraph.sdkcommon.schema.EdgeKind)2 GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)2 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)2 ByteString (com.google.protobuf.ByteString)2 ArrayList (java.util.ArrayList)2 AddEdgeKindOperation (com.alibaba.graphscope.groot.operation.ddl.AddEdgeKindOperation)1 RemoveEdgeKindOperation (com.alibaba.graphscope.groot.operation.ddl.RemoveEdgeKindOperation)1 EdgeTableIdEntry (com.alibaba.maxgraph.proto.groot.EdgeTableIdEntry)1 TypeDefPb (com.alibaba.maxgraph.proto.groot.TypeDefPb)1 VertexTableIdEntry (com.alibaba.maxgraph.proto.groot.VertexTableIdEntry)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1