Home > Software design >  Python - connecting to Neptune using gremlin
Python - connecting to Neptune using gremlin

Time:10-21

I am trying to connect to Neptune using Python from EC2 instance.

Python code:

from __future__  import print_function  # Python 2/3 compatibility

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

graph = Graph()

remoteConn = DriverRemoteConnection('wss://my_end_point:8182/gremlin','g')
g = graph.traversal().withRemote(remoteConn)

print(g.V().has("system.tenantId", "sample_tenantId").count())
remoteConn.close()

rather than executing gremlin query . its giving output as it is

output:

    [['V'], ['has', 'system.tenantId', 'sample_tenantId'], ['count']]

question: why its not taking gremlin query?

Please note: Connection is proper and I got output as mentioned in the link: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-python.html

output:    [v[sample_RETURN_D_H], v[sample_IND]] 

CodePudding user response:

Gremlin queries are lazily evaluated, so you must add a terminal step to your query for it to be executed by the server. If you change your line to add one of these steps as shown below, then it will be executed by the server.

print(g.V().has("system.tenantId", "sample_tenantId").count().next())
  • Related