use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue in project GraphScope by alibaba.
the class DataBuildMapper method buildPropertiesMap.
private Map<Integer, PropertyValue> buildPropertiesMap(GraphElement typeDef, String[] items, Map<Integer, Integer> columnMapping) {
Map<Integer, PropertyValue> operationProperties = new HashMap<>(columnMapping.size());
columnMapping.forEach((colIdx, propertyId) -> {
GraphProperty propertyDef = typeDef.getProperty(propertyId);
if (propertyDef == null) {
throw new PropertyDefNotFoundException("property [" + propertyId + "] not found in [" + typeDef.getLabel() + "]");
}
if (colIdx >= items.length) {
throw new IllegalArgumentException("label [" + typeDef.getLabel() + "], invalid mapping [" + colIdx + "] -> [" + propertyId + "], data [" + items + "]");
}
DataType dataType = propertyDef.getDataType();
String val = items[colIdx];
if (ldbcCustomize) {
String name = propertyDef.getName();
switch(name) {
case "creationDate":
case "joinDate":
val = converteDate(val);
break;
case "birthday":
val = val.replace("-", "");
break;
}
}
PropertyValue propertyValue = new PropertyValue(dataType, val);
operationProperties.put(propertyId, propertyValue);
});
return operationProperties;
}
use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue in project GraphScope by alibaba.
the class DataEncoder method getHashId.
private long getHashId(int labelId, Map<Integer, PropertyValue> operationProperties, List<Integer> pkIds) {
List<byte[]> pks = new ArrayList<>(pkIds.size());
for (int pkId : pkIds) {
PropertyValue propertyValue = operationProperties.get(pkId);
if (propertyValue == null) {
throw new InvalidDataException("label [" + labelId + "], propertyId [" + pkId + "]");
}
byte[] valBytes = propertyValue.getValBytes();
pks.add(valBytes);
}
return PkHashUtils.hash(labelId, pks);
}
use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue 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.maxgraph.sdkcommon.schema.PropertyValue 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));
}
use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue 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)));
}
Aggregations