0

I am using DSE graph to load data from a excel and preparing addE gremlin queries through java code and at last executing them over DSE graph.

In current testing need to fire 4,00,000 addE gremlin queries with two edge labels.

1) What is best practice to finish this execution in few minutes ? Right now i am giving gremlin queries in 1000 batch to dseSession.executeGraph(new SimpleGraphStatement("")) which leading to exception Method code too large! at groovyjarjarasm.asm.MethodWriter

2) For edge labels in this usecase, my schema defined as single cardinality. Also using custom vertex ids for vertexes. So if a edge already exist then DSE should just ignore it without any exception ?

user2572801
  • 151
  • 1
  • 2
  • 11

1 Answers1

1

The query parameter should be a simple array that looks like this:

[[from1, to1, label1], [from2, to2, label2], ...]

Then your script should look like this:

for (def triple in arg) {
  def (id1, id2, lbl) = triple
  def v1 = graph.vertices(id1).next()
  def v2 = graph.vertices(id2).next()
  if (!g.V(v1).outE(lbl).filter(inV().is(v2)).hasNext()) {
    v1.addEdge(lbl, v2)
  }
}

Alternatively:

for (def triple in arg) {
  def (id1, id2, lbl) = triple
  def v1 = graph.vertices(id1).next()
  if (!g.V(v1).outE(lbl).filter(inV().hasId(id2)).hasNext()) {
    v1.addEdge(lbl, graph.vertices(id2).next())
  }
}

Try both variants; at least one of them should outperform any other solution.

Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34
  • logic of both scripts i understood clearly, please guide how to use this script in Java code for testing ? – user2572801 May 30 '17 at 13:12
  • You can find examples for query / scripts with parameters here: https://github.com/datastax/java-dse-driver/tree/1.2.x/manual/graph#query-parameters – Daniel Kuppitz May 30 '17 at 13:33
  • ok thanks will test it, another concern is above script before every write it is doing a read in if condition even if most edges are new....is there a better alternative for this ? – user2572801 Jun 01 '17 at 07:34
  • Well, either all edges are new or you have to read first to figure out if it's new or if it already exists. There's no magic that can tell you whether an edge exists or not without an upfront read. – Daniel Kuppitz Jun 01 '17 at 10:56