Search in sources :

Example 6 with VertexRecordKey

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 + "]");
    }
}
Also used : VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) DataRecordPb(com.alibaba.graphscope.proto.write.DataRecordPb) WriteTypePb(com.alibaba.graphscope.proto.write.WriteTypePb) EdgeRecordKey(com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey)

Example 7 with VertexRecordKey

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);
}
Also used : VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) EdgeRecordKey(com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey) WriteRequestPb(com.alibaba.graphscope.proto.write.WriteRequestPb)

Example 8 with VertexRecordKey

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);
}
Also used : VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) WriteRequestPb(com.alibaba.graphscope.proto.write.WriteRequestPb)

Example 9 with VertexRecordKey

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));
}
Also used : EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) VertexId(com.alibaba.graphscope.groot.operation.VertexId) EdgeRecordKey(com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) EdgeId(com.alibaba.graphscope.groot.operation.EdgeId) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Example 10 with VertexRecordKey

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));
}
Also used : EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) VertexId(com.alibaba.graphscope.groot.operation.VertexId) EdgeRecordKey(com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) EdgeId(com.alibaba.graphscope.groot.operation.EdgeId) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Aggregations

VertexRecordKey (com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey)10 VertexId (com.alibaba.graphscope.groot.operation.VertexId)6 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)6 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)6 PropertyValue (com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 EdgeRecordKey (com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey)5 EdgeId (com.alibaba.graphscope.groot.operation.EdgeId)3 EdgeKind (com.alibaba.maxgraph.sdkcommon.schema.EdgeKind)3 WriteRequestPb (com.alibaba.graphscope.proto.write.WriteRequestPb)2 DataRecordPb (com.alibaba.graphscope.proto.write.DataRecordPb)1 WriteTypePb (com.alibaba.graphscope.proto.write.WriteTypePb)1