Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Update vertex not supported #76

@madhuvasu

Description

@madhuvasu

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

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions