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;
}
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));
}
Aggregations