Edge Query by ID from Gremlin-Python returns blank (v3.3.0)

1,407 views
Skip to first unread message

Peter Souza

unread,
Nov 7, 2017, 4:47:18 PM11/7/17
to Gremlin-users
The E() function will accept an edge object as a parameter, but not an ID value. When given an integer ID, it only ever returns a blank list, as though the ID does not exist in the graph.

in Python REPL:
>>> g.E().toList()
[e[362][292-wrote->318]]

>>> thing = g.E().toList()[0]
>>> g.E(thing).toList()
[e[362][292-wrote->318]]

>>> g.E(362).toList()
[]


This is different from V() which will happily work as advertised.
>>> g.V(236).both().toList()
[v[212], v[212], v[212]]
( Using version 3.3.0 of GremlinServer running locally, with Python libraries and connections/server configured as described in http://tinkerpop.apache.org/docs/current/reference/#gremlin-python.)


Additionally I cannot find any way to directly query or update an edge by ID, without first mocking up some kind of dummy edge-class object to pass. Am I missing something, or is this a bug?


Robert Dale

unread,
Nov 7, 2017, 5:14:58 PM11/7/17
to gremli...@googlegroups.com
Which graph database are you using?  This may have to do with the ID type.  For example, you can see in the gremlin console that the ID manager in TinkerGraph is generating Long IDs and looking up by Int won't work.

gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV().addE('e').to(__.addV())
==>e[2][0-e->1]
gremlin> g.E(2)
gremlin> 
gremlin> g.E(2L)
==>e[2][0-e->1]



Robert Dale

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/f8f0c4f2-be8c-4ca7-98dd-30063ad57e02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter Souza

unread,
Nov 7, 2017, 5:26:19 PM11/7/17
to Gremlin-users
Using Default tinkergraph, but note this is in Python, not the gremlin console. The syntax as shown works fine for Vertexes, just not Edges.

Robert Dale

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Peter Souza

unread,
Nov 7, 2017, 5:47:02 PM11/7/17
to Gremlin-users
As things go, you go back to test one more time and realize you missed part of it, so here's the update:
Querying edges by ID does work, but only for edges created by the initial server startup. Edges I add later do not seem to work.

Just after server startup, against the toy graph, everything works as expected:
>>> g.V().both().name.toList()
['lop', 'lop', 'lop', 'vadas', 'josh', 'josh', 'josh', 'marko', 'marko', 'marko', 'peter', 'ripple']
>>> g.E().toList()
e[7][1-knows->2], e[8][1-knows->4], e[9][1-created->3], e[10][4-created->5], e[11][4-created->3], e[12][6-created->3]]
>>> g.E(12).toList()
[e[12][6-created->3]]

My update writing a new edge into the graph:
>>> MarkoID = g.V().hasLabel('person').has('name','marko').toList()[0]
>>> a = g.V(MarkoID).next()
>>> friendID = g.V().hasLabel('person').has('name', 'peter').toList()[0]
>>> b = g.V(friendID).next()
>>> g.addE('buddies').from_(a).to(b).property('thisProp','5.0').property('thisOtherProp','6.0').toList()
[e[97][1-buddies->6]]
>>> g.E().toList()
e[97][1-buddies->6], e[7][1-knows->2], e[8][1-knows->4], e[9][1-created->3], e[10][4-created->5], e[11][4-created->3], e[12][6-created->3]]

And validation of issue:
>>> g.E(7).toList()
[e[7][1-knows->2]]
>>> g.E(97).toList()
[]

Robert Dale

unread,
Nov 7, 2017, 7:28:16 PM11/7/17
to gremli...@googlegroups.com
>>> g.E(2).toList()
[]
>>> g.E(long(2)).toList()
[e[2][0-e->1]]



Robert Dale

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/cf27b8aa-405c-4b03-b0d3-fbdb24a2b1ae%40googlegroups.com.

Peter Souza

unread,
Nov 7, 2017, 7:42:56 PM11/7/17
to Gremlin-users
I'm operating in Python3.6.2. As I understand it, the "Long" datatype does not exist independently of "int" in python3, so I'm not sure how I would translate what you're saying.

Testing with explicit Int typecasting does not change the behavior:
>>> g.E(int(12)).toList()
[e[12][6-created->3]]
>>> g.E(int(97)).toList()
[]
Where edge 12 was created by the server-side toy-graph builder, and edge 97 was added by me (see previous code.)

Also, as there is an entire serializer layer in between the python space and the server, the data types presented to the server would seem to be outside of my control right?

Thanks,
Peter

Robert Dale

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Robert Dale

unread,
Nov 7, 2017, 8:05:39 PM11/7/17
to gremli...@googlegroups.com
Ok, mine was in python 2.x.  I’m not sure how to type cast in 3.x or if there are any other gremlin-native mechanisms to do so. 

The sample graph is obviously created using ints for ids.  The id manager is creating long ids for new elements.  You can configure the id manager and what types it uses in TinkerGraph.  See http://tinkerpop.apache.org/docs/current/reference/#tinkergraph-gremlin




For more options, visit https://groups.google.com/d/optout.
--
Robert Dale

Peter Souza

unread,
Nov 7, 2017, 9:02:27 PM11/7/17
to Gremlin-users
I'm not sure I follow what you're saying exactly, but it did get me to a solution to the problem.

Out of the box, the gremlin-server-modern-py.yaml file that is used to start up the server for Gremlin-Python compatability calls
graphs: {
  graph
: conf/tinkergraph-empty.properties}

which originally only contains
gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
gremlin
.tinkergraph.vertexIdManager=LONG
i.e. no ID manager forcing for edgeID or vertexPropertyID. These being unset (therefore defaulting to ANY) seems to be incompatible with the default serializer implementation. My guess is that if they are not coerced to LONG, you get exactly what the documentation warns you of:
as GraphSON can lose the identifier’s type during serialization (i.e. it will assume Integer when the default for TinkerGraph is Long, which could lead to errors

Adding the other two ID settings to the conf/tinkergraph-empty.properties file, so it now reads
gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
gremlin
.tinkergraph.vertexIdManager=LONG
gremlin
.tinkergraph.edgeIdManager=LONG
gremlin
.tinkergraph.vertexPropertyIdManager=LONG

seems to have solved my problem.
Newly created edges are again query-able the same as the rest.
>>> g.E(13).toList()
[e[13][1-buddies->6]]


While we've solved it for my current needs, this really seems like a bug in the default implementation that ships with Gremlin Server for use with python. Is there a better place to post this issue and findings so it can get changed in the published version?

Thanks,
Peter

Robert Dale

unread,
Nov 7, 2017, 9:29:23 PM11/7/17
to gremli...@googlegroups.com

Robert Dale

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/127eaeca-ddb6-4f38-994c-ceaddabd3291%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages