Add Additional Property to Neptune DB

732 views Asked by At

I am trying to add additional property called "insert_date" to the existing vertices and edges. I tried

g.V().setProperty('insert_date',datetime('2020-10-06'))

Error:

{
  "requestId": "33cf8df5-3cbe-41ac-b650-5752debec04d",
  "code": "MalformedQueryException",
  "detailedMessage": "Query parsing failed at line 1, character position at 10, error message : token recognition error at: 'rop'"
}

I am trying the above command from Neptune Notebook.

It just adds new vertices with insert_date property. But I did not find the way to alter existing vertices or edges.

Please suggest if this is possible. As I want to implement delta extraction so that I can extract only new vertices or edges every time I run ETL.

Thanks

2

There are 2 answers

0
bechbd On BEST ANSWER

To add a property to an existing vertex in Gremlin you use the property() step. For example, if you wanted to add a property insert_date to a vertex with the id of A you would use the following statement:

g.V('A').property('insert_date', '2020-10-06')

The property() step will add or update the specified property to the new value. This will occur for all the current elements being passed in. For example, if you only wanted to update the elements that did not have an insert_date property you could do this via:

g.V().hasNot('insert_date').property('insert_date', '2020-10-06')

In each of these example the property will be added as part of an array of values. If you want to set the property to only contain a single value then you can use the property() step overload that takes the cardinality like this:

g.V('A').property(Cardinality.single, 'insert_date', '2020-10-06')

One thing to note in the code you have listed above. While Neptune does support the datetime() function for string-based queries, if you are not using a GLV then you will need to create this value and pass in a Native Date/Time as described here.

1
Raju On

Below Command worked to add additional properties to existing Graph.

g.V().property("insert_date","2020-01-01 00:00:00")