2

I am using OrientDB 2.1.4 and blueprints-core-2.6.0.

I have a requirement to update values on an existing Vertex or creating a new Vertex if not present. (expected 30k vertices every 45 seconds)

My vertex class is : Device(Name, Type, ActiveSessionCount) - "Name" for each Device is a unique entity.

Need to update ActiveSessionCount on device if device exists, else create a new Device vertex.

if (graph.getVertices(keyName, key).iterator().hasNext()) {
    vertex = (OrientVertex) graph.getVertices(keyName, key).iterator().next();
} else {
    vertex = graph.addVertex(className, attributeName, key);
}

I am trying to check if a vertex exists, if a vertex already exists, I have fetched the Vertex object for further update, else created a new Vertex Object.

Although, this works, it is taking a couple of minutes to execute for 30k records, while I need to achieve the same in 45 seconds.

cheffe
  • 9,345
  • 2
  • 46
  • 57

1 Answers1

1

Try with UPSERT.

UPSERT updates a record if it already exists, or inserts a new record if it does not, all in a single statement.

g.command(new OCommandSQL("update Device set Name='Device 3',Type='Type 3',ActiveSessionCount=3  upsert where Name='Device 3'' "));

Regards,

Michela

Michela Bonizzi
  • 2,622
  • 1
  • 9
  • 16
  • Hi Michela, My requirement is to do a bulk update on edges and vertices. I have approximately 150,000 vertices and 175,000 edges to be created on those vertices. What will be the best way to progress? With my current code i am able to complete the processing in 35 minutes :( I need to cut it down to lesser than 5 minutes. – Nandna Chowdhury Nov 04 '15 at 17:13
  • Hi Nandna, Could you send us the db or your java class or both,please? So we can do more test, thank you. – Michela Bonizzi Nov 05 '15 at 08:18