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);
}
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);
}
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);
}
Aggregations