本文介绍了使用TinkerPop的gremlinpython将字符串gremlin查询发送到Amazon海王星数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以执行以下操作来创建连接,然后将该连接附加到图形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

推荐答案

以下是从Gremlin Python调用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()

完整示例is here

这篇关于使用TinkerPop的gremlinpython将字符串gremlin查询发送到Amazon海王星数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:34