use of com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey in project GraphScope by alibaba.
the class WriteRequest method parseProto.
public static WriteRequest parseProto(WriteRequestPb proto) {
WriteTypePb writeTypePb = proto.getWriteType();
DataRecordPb dataRecordPb = proto.getDataRecord();
Map<String, Object> properties = Collections.unmodifiableMap(dataRecordPb.getPropertiesMap());
DataRecordPb.RecordKeyCase recordKeyCase = dataRecordPb.getRecordKeyCase();
switch(recordKeyCase) {
case VERTEX_RECORD_KEY:
VertexRecordKey vertexRecordKey = VertexRecordKey.parseProto(dataRecordPb.getVertexRecordKey());
return buildWriteVertexRequest(writeTypePb, new DataRecord(vertexRecordKey, properties));
case EDGE_RECORD_KEY:
EdgeRecordKey edgeRecordKey = EdgeRecordKey.parseProto(dataRecordPb.getEdgeRecordKey());
return buildWriteEdgeRequest(writeTypePb, new DataRecord(edgeRecordKey, properties));
default:
throw new IllegalArgumentException("Invalid record key case [" + recordKeyCase + "]");
}
}
use of com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey in project GraphScope by alibaba.
the class MaxGraphClient method addEdge.
public void addEdge(String label, String srcLabel, String dstLabel, Map<String, String> srcPk, Map<String, String> dstPk, Map<String, String> properties) {
VertexRecordKey srcVertexKey = new VertexRecordKey(srcLabel, Collections.unmodifiableMap(srcPk));
VertexRecordKey dstVertexKey = new VertexRecordKey(dstLabel, Collections.unmodifiableMap(dstPk));
EdgeRecordKey edgeRecordKey = new EdgeRecordKey(label, srcVertexKey, dstVertexKey);
WriteRequestPb writeRequest = WriteRequestPb.newBuilder().setWriteType(WriteTypePb.INSERT).setDataRecord(DataRecordPb.newBuilder().setEdgeRecordKey(edgeRecordKey.toProto()).putAllProperties(properties).build()).build();
this.batchWriteBuilder.addWriteRequests(writeRequest);
}
use of com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey in project GraphScope by alibaba.
the class MaxGraphClient method addVertex.
public void addVertex(String label, Map<String, String> properties) {
VertexRecordKey vertexRecordKey = new VertexRecordKey(label);
WriteRequestPb writeRequest = WriteRequestPb.newBuilder().setWriteType(WriteTypePb.INSERT).setDataRecord(DataRecordPb.newBuilder().setVertexRecordKey(vertexRecordKey.toProto()).putAllProperties(properties).build()).build();
this.batchWriteBuilder.addWriteRequests(writeRequest);
}
use of com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey in project GraphScope by alibaba.
the class GraphWriter method addDeleteEdgeOperation.
private void addDeleteEdgeOperation(OperationBatch.Builder batchBuilder, GraphSchema schema, DataRecord dataRecord) {
EdgeId edgeId;
EdgeKind edgeKind;
EdgeTarget edgeTarget = dataRecord.getEdgeTarget();
if (edgeTarget != null) {
edgeId = edgeTarget.getEdgeId();
edgeKind = edgeTarget.getEdgeKind();
} else {
EdgeRecordKey edgeRecordKey = dataRecord.getEdgeRecordKey();
VertexRecordKey srcVertexRecordKey = edgeRecordKey.getSrcVertexRecordKey();
VertexRecordKey dstVertexRecordKey = edgeRecordKey.getDstVertexRecordKey();
String label = edgeRecordKey.getLabel();
GraphElement edgeDef = schema.getElement(label);
GraphElement srcVertexDef = schema.getElement(srcVertexRecordKey.getLabel());
GraphElement dstVertexDef = schema.getElement(dstVertexRecordKey.getLabel());
int labelId = edgeDef.getLabelId();
Map<Integer, PropertyValue> srcVertexPkVals = parseRawProperties(srcVertexDef, srcVertexRecordKey.getProperties());
long srcVertexHashId = getHashId(srcVertexDef.getLabelId(), srcVertexPkVals, srcVertexDef);
Map<Integer, PropertyValue> dstVertexPkVals = parseRawProperties(dstVertexDef, dstVertexRecordKey.getProperties());
long dstVertexHashId = getHashId(dstVertexDef.getLabelId(), dstVertexPkVals, dstVertexDef);
long edgeInnerId = edgeRecordKey.getEdgeInnerId();
edgeId = new EdgeId(new VertexId(srcVertexHashId), new VertexId(dstVertexHashId), edgeInnerId);
edgeKind = EdgeKind.newBuilder().setEdgeLabelId(new LabelId(labelId)).setSrcVertexLabelId(new LabelId(srcVertexDef.getLabelId())).setDstVertexLabelId(new LabelId(dstVertexDef.getLabelId())).build();
}
batchBuilder.addOperation(new DeleteEdgeOperation(edgeId, edgeKind, true));
batchBuilder.addOperation(new DeleteEdgeOperation(edgeId, edgeKind, false));
}
use of com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey in project GraphScope by alibaba.
the class GraphWriter method addUpdateEdgeOperation.
private void addUpdateEdgeOperation(OperationBatch.Builder batchBuilder, GraphSchema schema, DataRecord dataRecord) {
EdgeId edgeId;
EdgeKind edgeKind;
GraphElement edgeDef;
EdgeTarget edgeTarget = dataRecord.getEdgeTarget();
Map<String, Object> properties = dataRecord.getProperties();
if (edgeTarget != null) {
edgeId = edgeTarget.getEdgeId();
edgeKind = edgeTarget.getEdgeKind();
edgeDef = schema.getElement(edgeKind.getEdgeLabelId().getId());
} else {
EdgeRecordKey edgeRecordKey = dataRecord.getEdgeRecordKey();
VertexRecordKey srcVertexRecordKey = edgeRecordKey.getSrcVertexRecordKey();
VertexRecordKey dstVertexRecordKey = edgeRecordKey.getDstVertexRecordKey();
String label = edgeRecordKey.getLabel();
edgeDef = schema.getElement(label);
GraphElement srcVertexDef = schema.getElement(srcVertexRecordKey.getLabel());
GraphElement dstVertexDef = schema.getElement(dstVertexRecordKey.getLabel());
int labelId = edgeDef.getLabelId();
Map<Integer, PropertyValue> srcVertexPkVals = parseRawProperties(srcVertexDef, srcVertexRecordKey.getProperties());
long srcVertexHashId = getHashId(srcVertexDef.getLabelId(), srcVertexPkVals, srcVertexDef);
Map<Integer, PropertyValue> dstVertexPkVals = parseRawProperties(dstVertexDef, dstVertexRecordKey.getProperties());
long dstVertexHashId = getHashId(dstVertexDef.getLabelId(), dstVertexPkVals, dstVertexDef);
long edgeInnerId = edgeRecordKey.getEdgeInnerId();
edgeId = new EdgeId(new VertexId(srcVertexHashId), new VertexId(dstVertexHashId), edgeInnerId);
edgeKind = EdgeKind.newBuilder().setEdgeLabelId(new LabelId(labelId)).setSrcVertexLabelId(new LabelId(srcVertexDef.getLabelId())).setDstVertexLabelId(new LabelId(dstVertexDef.getLabelId())).build();
}
Map<Integer, PropertyValue> propertyVals = parseRawProperties(edgeDef, properties);
batchBuilder.addOperation(new UpdateEdgeOperation(edgeId, edgeKind, propertyVals, true));
batchBuilder.addOperation(new UpdateEdgeOperation(edgeId, edgeKind, propertyVals, false));
}
Aggregations