我们可以执行以下操作来创建连接,然后将连接附加到图形g对象,然后使用g内联地镜像gremlin查询。
from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
Create a GraphTraversalSource which is the basis for all Gremlin traversals:
graph = Graph()
connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
g = graph.traversal().withRemote(connection)
g.V().limit(2).toList()但是,我想像下面这样提交字符串grelmin查询,
connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
query = "g.V().limit(2).toList()"
connection.submit(query)然后我得到了下面的错误。看起来我没有正确地调用submit()函数,也找不到关于这个函数的任何文档或示例。请帮帮忙。
[ERROR] AttributeError: 'str' object has no attribute 'source_instructions'
Traceback (most recent call last):
File "/var/task/sentry_sdk/integrations/aws_lambda.py", line 152, in sentry_handler
return handler(aws_event, aws_context, *args, **kwargs)
response = remoteConn.submit(query)
File "/var/task/gremlin_python/driver/driver_remote_connection.py", line 56, in submit
result_set = self._client.submit(bytecode, request_options=self._extract_request_options(bytecode))
File "/var/task/gremlin_python/driver/driver_remote_connection.py", line 81, in _extract_request_options
options_strategy = next((x for x in bytecode.source_instructions发布于 2021-12-19 00:19:11
下面是从Gremlin调用submit的一个示例,您需要以稍微不同的方式创建连接:
client = client.Client('ws://localhost:8182/gremlin','g')
query = """
g.V().hasLabel('airport').
sample(30).
order().by('code').
local(__.values('code','city').fold()).
toList()
"""
result = client.submit(query)
future_results = result.all()
results = future_results.result()
client.close()完整的示例就在这里
https://stackoverflow.com/questions/70400302
复制相似问题