3

I cannot select a specific vertex, by executing g.V(3640).valueMap(true).unfold(). Any command which contains an ID between the parentheses in the g.V() command does not seem to work.

This is what I did:

I'm new to Graph databases and experimenting with the Gremlin console. I started by creating an instance:

graph = TinkerGraph.open()
g=graph.traversal()

and loading sample data by importing a .graphml database file:

g.io(graphml()).readGraph('/full/path/to/air-routes-latest.graphml')

which seemed to work fine because a count gives a nice result back

gremlin> g.V().count()
==>3642

Unfortunately the following does not work:

gremlin> g.V(3640).valueMap(true).unfold()

Which I think is odd, because by executing the following

gremlin> g.V()
==>v[3640]
==>v[2306]
...

the ID does seem to exist. Any ideas why I cannot access a specific ID? I tried different commands but g.V() seems to work fine, and g.V(3640) does not. Is it because I use TinkerGraph instead of a Gremlin database, of what might be the problem?

EDIT:

It seems that my id's were saved as strings, because g.V("2").valueMap(true).unfold() does give me results.

Erik van de Ven
  • 4,747
  • 6
  • 38
  • 80

1 Answers1

5

I think you likely have an issue with the "type" of the identifier. I suspect that if you do:

g.V(3640L)

that you will get the vertex you want. By default, TinkerGraph handles id equality with equals() so if you try to find an integer when the id is a long it will act like it's not there. You can modify that default if you like with an IdManager configuration discussed here. Note that this is also discussed in more detail in Practical Gremlin.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • 1
    I just discovered I do get results, by putting the number between parentheses, like `g.V("3640")`. So it might be stored as a string? I am reading Kelvin R. Lawrence's book, and I was stuck at this point at one of the first few examples, so hard to find where the problem is exactly with so little knowledge. `g.V(3640L)` did not work for me. – Erik van de Ven Sep 18 '18 at 15:39
  • I have marked your answer as the solution, because the link you provided, which shows me how to actually tell TinkerGraph how ID's should be stored, really helped. Now even the query `g.V(3640).valueMap()` without parentheses, works. Thanks! – Erik van de Ven Sep 18 '18 at 15:46
  • 1
    Hi Erik, in the book I have an example of how to establish the ID managers. I also saw your issue. I will add a tip box to clarify this is expected at the point where you found the text confusing. Also be aware that if you move beyond TinkerGraph at some point, different Graph DB back ends may have specific ID rules. For example, some only allow string IDs etc. – Kelvin Lawrence Sep 19 '18 at 14:21