salvob
salvob

Reputation: 1370

upserting data in TitanDB

I am using TitanDB with Cassandra as storage and ElasticSearch as Index. I found out that everytime you add Vertex in TitanDB, it generates a unique identifier.

All the elements I am adding into it, has already an identifier, this has been added as property of the Vertex. My question is: If I will add again a Vertex with the same id, How does TitanDB recognise that it is a duplicate? Is it possible update element on duplicate key ? Or you have first to make a query within TitanDB? If so, isn't it a terrible waste of time doing so?

Upvotes: 0

Views: 176

Answers (1)

stephen mallette
stephen mallette

Reputation: 46226

There is no direct method for "upsert". As noted above, in the comment on the question, the "getOrCreate" approach is the standard way to do this. So, "yes" you would need to do a lookup via index on your identifier property.

Titan can detect duplicates if you establish your indexed property with a unique constraint:

mgmt = graph.openManagement()
name = mgmt.getPropertyKey('name')
mgmt.buildIndex('byNameUnique', Vertex.class).addKey(name).unique().buildCompositeIndex()
mgmt.commit()

If the same property value is applied twice now, an exception will be generated on commit of the transaction. Use unique indexes wisely as they will affect performance especially if you expect heavy contention on the property that the unique is applied to.

Upvotes: 3

Related Questions