Search in sources :

Example 16 with PropertyValue

use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue in project GraphScope by alibaba.

the class GraphWriter method parseRawProperties.

public static Map<Integer, PropertyValue> parseRawProperties(GraphElement graphElement, Map<String, Object> properties) {
    Map<Integer, PropertyValue> res = new HashMap<>();
    if (properties != null) {
        properties.forEach((propertyName, valString) -> {
            GraphProperty propertyDef = graphElement.getProperty(propertyName);
            if (propertyDef == null) {
                throw new PropertyDefNotFoundException("property [" + propertyName + "] not found in [" + graphElement.getLabel() + "]");
            }
            int id = propertyDef.getId();
            DataType dataType = propertyDef.getDataType();
            PropertyValue propertyValue = new PropertyValue(dataType, valString);
            res.put(id, propertyValue);
        });
    }
    return res;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) HashMap(java.util.HashMap) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) DataType(com.alibaba.maxgraph.compiler.api.schema.DataType) PropertyDefNotFoundException(com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException)

Example 17 with PropertyValue

use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue 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

PropertyValue (com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)17 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 VertexId (com.alibaba.graphscope.groot.operation.VertexId)6 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)6 VertexRecordKey (com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey)6 EdgeKind (com.alibaba.maxgraph.sdkcommon.schema.EdgeKind)4 PropertyDef (com.alibaba.maxgraph.sdkcommon.schema.PropertyDef)4 TypeDef (com.alibaba.maxgraph.sdkcommon.schema.TypeDef)4 EdgeId (com.alibaba.graphscope.groot.operation.EdgeId)3 EdgeRecordKey (com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey)3 DdlExecutors (com.alibaba.graphscope.groot.schema.ddl.DdlExecutors)2 CreateVertexTypeRequest (com.alibaba.graphscope.groot.schema.request.CreateVertexTypeRequest)2 DdlRequestBatch (com.alibaba.graphscope.groot.schema.request.DdlRequestBatch)2 PropertyDefNotFoundException (com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException)2 GraphProperty (com.alibaba.maxgraph.compiler.api.schema.GraphProperty)2 GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 SnapshotListener (com.alibaba.graphscope.groot.SnapshotListener)1