我已经安装了Gremlin Server,并使用它从我的Python脚本连接到Neptune数据库,但是当我尝试运行一些gremlin查询时:
g.V().hasLabel('person').as('e').order().by('age', desc).limit(4).select('e').values('age').toList()
表示“ desc”未知。它需要tinkerpop依赖项和包-> org.apache.tinkerpop.gremlin.process.traversal.Order。* ..这是一个Java包,如何将其导入我的Python脚本中?
您不需要Gremlin Server即可连接到Neptune。 Neptune在私有VPC中公开了Gremlin兼容的终结点。要连接您的代码,将需要有权在该VPC中运行,例如从堡垒主机。在那里,您可以连接到海王星,您将需要安装gremlin-python软件包:
pip3 install --user gremlinpython
从那里,您需要包括在TinkerPop文档here中可以找到的常见导入。
一旦导入,就可以使用如下函数进行连接:
def connect_to_neptune():
"""Creates a connection to Neptune and returns the traversal source"""
server = 'air-routes.cluster-cei5pmtr7fqq.us-west-2.neptune.amazonaws.com'
port = 8182
endpoint = f'wss://{server}:{port}/gremlin'
logger.info(endpoint)
connection = DriverRemoteConnection(endpoint, 'g')
gts = traversal().withRemote(connection)
return (gts, connection)
其他信息可以在TinkerPop文档中找到:http://tinkerpop.apache.org/docs/current/reference/#gremlin-python