-
Notifications
You must be signed in to change notification settings - Fork 92
Update vertex not supported #76
Description
Hi,
Currently, the utils project doesn't support updates to a vertex.
I was wondering if we could create a new set of classes that can be called VertexUpdaterWorker (or something like that..) that tries to fetch the vertex that already exists in the graph DB and then have the v.property(propName, convertedValue); update the vertex?
For example, with the current code, I can ingest the following data using the DataLoader.loadVertex() utility.
input.csv contains:
cust_id, is_active
1347, TRUE
1348, FALSE
The datamapper.json contains:
"vertexMap": {
"input.csv": {
"[VertexLabel]": "customer",
"is_active": "is_active"
"cust_id": "node_id"
}
},
"edgeMap": {}
}
In order to update the above nodes, I propose we have a couple of new fields in the datamapper.json that signify which field should be searched for in the graph DB and what field it maps to on the input CSV.
For example:
{
"vertexMap": {
"update.csv": {
"[VertexLabel]": "customer",<===== this signifies the vertex type that should be updated
"[SearchGraph]": "node_id", <==== this signifies which vertex should be updated
"[SearchCsv]": "cust_id", <======= this signifies node_id is mapped to cust_id in the CSV
"is_active": "is_active" <========= this is same as before
}
},
"edgeMap": {}
}
where update.csv contains:
cust_id, is_active 1347, FALSE 1348, TRUE
We can then create a new acceptRecord that does the below:
` JanusGraphVertex v;
// Find the vertex to be updated
try {
v = (JanusGraphVertex) graphTransaction.traversal().V().hasLabel(vertexLabel).has(searchGraphLabel, record.get(searchCsvLabel)).next();
} catch (Exception e) {
return;
}
try {
// set the properties of the vertex
for (String column : record.keySet()) {
// Find the value, property to be updated
String value = record.get(column);
// If value="" or it is a vertex label then skip it
if (value == null || value.length() == 0 || column.equals(vertexLabelFieldName))
continue;
String propName = (String) getPropertiesMap().get(column);
if (propName == null) {
continue;
}
// Update the value from String to property's datayype, ex. date & time
Object convertedValue = BatchHelper.convertPropertyValue(value,
graphTransaction.getPropertyKey(propName).dataType());
// Write property and value to vertex
v.property(propName, convertedValue);
}
} catch (Exception e) {
return;
}
`