1

I'm using titan db 1.0.0 backed by a local dynamodb instance (which uses the 3.0 tinkerpop stack). I've spent more time than I'd like to admit trying to figure out why drop() wasn't working. In my use case I'm trying to remove a specific edge found via a traversal, but even graph.traversal().V().drop() wasn't working. I did much googling, but perhaps not with the right keywords. I finally figured out the issue which I'll specify in my answer. Hopefully others find this useful.

jgreen
  • 1,132
  • 2
  • 14
  • 18
  • 1
    Possible duplicate of [Gremlin remove all Vertex](http://stackoverflow.com/questions/12814305/gremlin-remove-all-vertex) – stephen mallette Mar 16 '16 at 13:19
  • @stephenmallette the V().drop() was just a straightforward use case of drop - though I do see that an answer at the bottom of the post you provided does mention the iterate(). I've edited to clarify that this was more an issue of drop() not working as I expected. – jgreen Mar 16 '16 at 17:21

3 Answers3

4

I finally remembered reading somewhere (unfortunately I can't find it now to share the link edit:see the link provided by Stephen Mallete), that when dealing with gremlin in java-land, you needed to explicitly iterate the traversal.

So the trick was graph.traversal().V().drop().iterate(). Note this is not needed when using the gremlin console (at least with 3.0). You can just use graph.traversal().V().drop().

jgreen
  • 1,132
  • 2
  • 14
  • 18
  • 1
    fwiw, `drop()` and iteration specifically is discussed here: http://tinkerpop.apache.org/docs/3.1.1-incubating/tutorials/the-gremlin-console/#result-iteration – stephen mallette Mar 16 '16 at 13:19
  • @stephenmallette some feedback I have on the tinkerpop documentation is that while I fully understand using the console for tutorials and such, I have to believe that most real-world use is going to be through an api such as I'm using. It would make sense to me to tailor the documentation to that use, or at the very least call out in each case where the gotchas exist. It makes no sense to me that this need to iterate isn't mentioned here: http://tinkerpop.apache.org/docs/3.1.1-incubating/reference/#drop-step. – jgreen Mar 16 '16 at 17:34
  • you always need to `iterate()` whether it's drop step or anything else. `x = g.V()` returns nothing into "x" - that's just a `Traversal`. to add information on iterate in drop step would mean having to add it to all steps. it is a general concept central to gremlin. that's why i focused so hard on it in the tutorial. while most people will develop apps, they (should) start with the console which is why much of our docs are written the way they are (and we can generate them from code so there are never bugs in the docs). We will be writing more docs/tutorials on app development topics soon. – stephen mallette Mar 17 '16 at 11:34
  • I guess in my way of thinking the need to iterate is obvious in steps where you are expecting some kind of result set. But drop feels like a void. So it would only be my expectation to call it out as a gotcha in those type of steps. As someone so close to the project this all probably seems painfully obvious to you. I'm offering my suggestion as someone of at least moderate intelligence in this industry, who is coming from java (not groovy or similar), and probably represents a fair percentage of the users you'd like to attract. – jgreen Mar 18 '16 at 18:19
  • I went through the tutorial which is probably why it finally came to mind, but at the time of going through a tutorial I'm just trying to wrap my head around everything; it is unlikely I'll fully appreciate the impact of all asides, 'notes', etc. – jgreen Mar 18 '16 at 18:28
1

You could try the following to clear your graph:

TitanGraph titanGraph = TitanFactory.open(config);
TitanCleanup.clear(graph);

This essentially drops the keyspace in Cassandra and clears the graph completely including indexing.

Filipe Teixeira
  • 3,565
  • 1
  • 25
  • 45
  • Good to know, thanks. My actual use case is to remove a single vertex or edge. The V().drop() was just a case where I could have confidence that my issue wasn't the command I was trying to use :) – jgreen Mar 16 '16 at 17:15
0

you need to commit it after traversal.

example:

graph.traversal().V().drop().iterate()
graph.tx().commit()