janusgraph-utils icon indicating copy to clipboard operation
janusgraph-utils copied to clipboard

Update vertex not supported

Open madhuvasu opened this issue 6 years ago • 3 comments

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

`

madhuvasu avatar Apr 02 '19 11:04 madhuvasu

Does this sound like a reasonable approach?

madhuvasu avatar Apr 02 '19 11:04 madhuvasu

Originally, when we introduce the importer, the main purpose is for bulk loading data in csv format into Janusgraph. Your proposal is trying to use the utility to update the graph db in batch? I think it's a good idea. Are you willing to implement this?

yhwang avatar Apr 03 '19 01:04 yhwang

Yes, I can implement this and send it across for review. Thanks!

madhuvasu avatar Apr 03 '19 15:04 madhuvasu