use of com.alibaba.graphscope.groot.operation.EdgeId in project GraphScope by alibaba.
the class MaxGraphImpl method addEdge.
@Override
public Edge addEdge(String label, Vertex src, Vertex dst, Map<String, Object> properties) {
GraphSchema schema = getSchema();
int edgeLabelId = schema.getElement(label).getLabelId();
EdgeKind edgeKind = EdgeKind.newBuilder().setEdgeLabelId(new LabelId(edgeLabelId)).setSrcVertexLabelId(new LabelId(src.id.typeId())).setDstVertexLabelId(new LabelId(dst.id.typeId())).build();
long innerId = ++startEdgeInnerId;
EdgeId edgeId = new EdgeId(new VertexId(src.id.id()), new VertexId(dst.id.id()), innerId);
EdgeTarget edgeTarget = new EdgeTarget(edgeKind, edgeId);
DataRecord dataRecord = new DataRecord(edgeTarget, properties);
WriteRequest writeRequest = new WriteRequest(OperationType.OVERWRITE_EDGE, dataRecord);
graphWriter.writeBatch(getClass().getCanonicalName(), this.writeSession, Arrays.asList(writeRequest));
return null;
}
use of com.alibaba.graphscope.groot.operation.EdgeId in project GraphScope by alibaba.
the class GraphWriter method addOverwriteEdgeOperation.
private void addOverwriteEdgeOperation(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 = this.edgeIdGenerator.getNextId();
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 OverwriteEdgeOperation(edgeId, edgeKind, propertyVals, true));
batchBuilder.addOperation(new OverwriteEdgeOperation(edgeId, edgeKind, propertyVals, false));
}
use of com.alibaba.graphscope.groot.operation.EdgeId 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.graphscope.groot.operation.EdgeId 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