Reputation: 379
I want to fetch all the edges and associated vertices from my AWS Neptune DB. In addition, I want the id, labels and properties for the nodes as well as edges.
My data is a stored as a property graph and I'm using gremlin-python to query it.
Below is a query which provides the required data when executed in the gremlin shell. However, trying to execute the same using gremlin-python throws an error.
g.V().bothE().otherV().limit(2).path().by(__.valueMap(true))
Python variant
from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.traversal import T
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
# Define a graph instance
graph = Graph()
# Connect to the neptune instance
try:
remoteConn = DriverRemoteConnection('wss://<YOUR_NEPTUNE_IP>:8182/gremlin', 'g')
g = graph.traversal().withRemote(remoteConn)
except:
print("Couldn't connect successfully with Neptune instance")
exit()
g.V().bothE().otherV().limit(2).path().by(__.valueMap(True))
Error
GremlinServerError: 498: {"requestId":"...","code":"UnsupportedOperationException","detailedMessage":"org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath cannot be cast to org.apache.tinkerpop.gremlin.structure.Element"}
Can someone provide me a way to get the required information? Be it by successfully converting the above query to Python or via some other query.
Upvotes: 3
Views: 3621
Reputation: 46206
Your traversal looks valid to me and in fact seems to work fine with TinkerGraph:
gremlin> g.V().bothE().otherV().limit(2).path().by(__.valueMap(true))
==>[[id:1,name:[marko],label:person,age:[29]],[id:9,weight:0.4,label:created],[id:3,name:[lop],lang:[java],label:software]]
==>[[id:1,name:[marko],label:person,age:[29]],[id:7,weight:0.5,label:knows],[id:2,name:[vadas],label:person,age:[27]]]
I would expect that to work. Perhaps that is a bug in Neptune? Note that you can get the same result by using select()
but it is a bit more verbose:
gremlin> g.V().as('a').bothE().as('b').otherV().as('c').limit(2).select('a','b','c').by(valueMap(true))
==>[a:[id:1,name:[marko],label:person,age:[29]],b:[id:9,weight:0.4,label:created],c:[id:3,name:[lop],lang:[java],label:software]]
==>[a:[id:1,name:[marko],label:person,age:[29]],b:[id:7,weight:0.5,label:knows],c:[id:2,name:[vadas],label:person,age:[27]]]
You can of course unfold()
the Map
instances produced by select()
to get the same output format as path()
gremlin> g.V().as('a').bothE().as('b').otherV().as('c').limit(2).select('a','b','c').by(valueMap(true)).map(unfold().select(values).fold())
==>[[id:1,name:[marko],label:person,age:[29]],[id:9,weight:0.4,label:created],[id:3,name:[lop],lang:[java],label:software]]
==>[[id:1,name:[marko],label:person,age:[29]],[id:7,weight:0.5,label:knows],[id:2,name:[vadas],label:person,age:[27]]]
Upvotes: 3