Python - 使用 gremlin 连接到 Neptune

Python - connecting to Neptune using gremlin

我正在尝试使用 Python 从 EC2 实例连接到 Neptune。

Python代码:

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()

而不是执行 gremlin 查询。它按原样给出输出

输出:

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

问题:为什么不采用 gremlin 查询?

请注意: 连接正确,我得到了 link 中提到的输出:https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-python.html

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

Gremlin 查询是延迟计算的,因此您必须在查询中添加 terminal step 才能由服务器执行。如果您更改您的行以添加这些步骤之一,如下所示,那么它将由服务器执行。

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