Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vertex not supported #76

Open
madhuvasu opened this issue Apr 2, 2019 · 3 comments
Open

Update vertex not supported #76

madhuvasu opened this issue Apr 2, 2019 · 3 comments

Comments

@madhuvasu
Copy link

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
Copy link
Author

Does this sound like a reasonable approach?

@yhwang
Copy link
Member

yhwang commented Apr 3, 2019

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?

@madhuvasu
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants