Search in sources :

Example 1 with VertexId

use of com.alibaba.graphscope.groot.operation.VertexId 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;
}
Also used : EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) EdgeId(com.alibaba.graphscope.groot.operation.EdgeId) VertexId(com.alibaba.graphscope.groot.operation.VertexId) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema)

Example 2 with VertexId

use of com.alibaba.graphscope.groot.operation.VertexId 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));
}
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 3 with VertexId

use of com.alibaba.graphscope.groot.operation.VertexId in project GraphScope by alibaba.

the class GraphWriter method addUpdateVertexOperation.

private void addUpdateVertexOperation(OperationBatch.Builder batchBuilder, GraphSchema schema, DataRecord dataRecord) {
    VertexRecordKey vertexRecordKey = dataRecord.getVertexRecordKey();
    Map<String, Object> properties = dataRecord.getProperties();
    String label = vertexRecordKey.getLabel();
    GraphElement vertexDef = schema.getElement(label);
    int labelId = vertexDef.getLabelId();
    Map<Integer, PropertyValue> pkVals = parseRawProperties(vertexDef, vertexRecordKey.getProperties());
    long hashId = getHashId(labelId, pkVals, vertexDef);
    Map<Integer, PropertyValue> propertyVals = parseRawProperties(vertexDef, properties);
    propertyVals.putAll(pkVals);
    batchBuilder.addOperation(new UpdateVertexOperation(new VertexId(hashId), new LabelId(labelId), propertyVals));
}
Also used : PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) VertexId(com.alibaba.graphscope.groot.operation.VertexId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Example 4 with VertexId

use of com.alibaba.graphscope.groot.operation.VertexId in project GraphScope by alibaba.

the class GraphWriter method addDeleteVertexOperation.

private void addDeleteVertexOperation(OperationBatch.Builder batchBuilder, GraphSchema schema, DataRecord dataRecord) {
    VertexRecordKey vertexRecordKey = dataRecord.getVertexRecordKey();
    String label = vertexRecordKey.getLabel();
    GraphElement vertexDef = schema.getElement(label);
    int labelId = vertexDef.getLabelId();
    Map<Integer, PropertyValue> pkVals = parseRawProperties(vertexDef, vertexRecordKey.getProperties());
    long hashId = getHashId(labelId, pkVals, vertexDef);
    batchBuilder.addOperation(new DeleteVertexOperation(new VertexId(hashId), new LabelId(labelId)));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) VertexId(com.alibaba.graphscope.groot.operation.VertexId) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Example 5 with VertexId

use of com.alibaba.graphscope.groot.operation.VertexId in project GraphScope by alibaba.

the class GraphWriter method addOverwriteVertexOperation.

private void addOverwriteVertexOperation(OperationBatch.Builder batchBuilder, GraphSchema schema, DataRecord dataRecord) {
    VertexRecordKey vertexRecordKey = dataRecord.getVertexRecordKey();
    Map<String, Object> properties = dataRecord.getProperties();
    String label = vertexRecordKey.getLabel();
    GraphElement vertexDef = schema.getElement(label);
    int labelId = vertexDef.getLabelId();
    Map<Integer, PropertyValue> pkVals = parseRawProperties(vertexDef, vertexRecordKey.getProperties());
    Map<Integer, PropertyValue> propertyVals = parseRawProperties(vertexDef, properties);
    propertyVals.putAll(pkVals);
    long hashId = getHashId(labelId, propertyVals, vertexDef);
    batchBuilder.addOperation(new OverwriteVertexOperation(new VertexId(hashId), new LabelId(labelId), propertyVals));
}
Also used : PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) VertexId(com.alibaba.graphscope.groot.operation.VertexId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Aggregations

VertexId (com.alibaba.graphscope.groot.operation.VertexId)8 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)8 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)6 VertexRecordKey (com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey)6 PropertyValue (com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 EdgeId (com.alibaba.graphscope.groot.operation.EdgeId)4 EdgeKind (com.alibaba.maxgraph.sdkcommon.schema.EdgeKind)4 EdgeRecordKey (com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey)3 CompletionCallback (com.alibaba.graphscope.groot.CompletionCallback)1 BatchSender (com.alibaba.graphscope.groot.ingestor.BatchSender)1 StoreWriter (com.alibaba.graphscope.groot.ingestor.StoreWriter)1 MetaService (com.alibaba.graphscope.groot.meta.MetaService)1 MetricsCollector (com.alibaba.graphscope.groot.metrics.MetricsCollector)1 OperationBatch (com.alibaba.graphscope.groot.operation.OperationBatch)1 OperationBlob (com.alibaba.graphscope.groot.operation.OperationBlob)1 StoreDataBatch (com.alibaba.graphscope.groot.operation.StoreDataBatch)1 OverwriteVertexOperation (com.alibaba.graphscope.groot.operation.dml.OverwriteVertexOperation)1 Configs (com.alibaba.maxgraph.common.config.Configs)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1