首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用TinkerPop的gremlinpython将字符串gremlin查询发送到Amazon数据库

使用TinkerPop的gremlinpython将字符串gremlin查询发送到Amazon数据库
EN

Stack Overflow用户
提问于 2021-12-18 01:09:55
回答 1查看 347关注 0票数 0

我们可以执行以下操作来创建连接,然后将连接附加到图形g对象,然后使用g内联地镜像gremlin查询。

代码语言:javascript
复制
    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查询,

代码语言:javascript
复制
    connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
    
    query = "g.V().limit(2).toList()"
    connection.submit(query)

然后我得到了下面的错误。看起来我没有正确地调用submit()函数,也找不到关于这个函数的任何文档或示例。请帮帮忙。

代码语言:javascript
复制
[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
EN

回答 1

Stack Overflow用户

发布于 2021-12-19 00:19:11

下面是从Gremlin调用submit的一个示例,您需要以稍微不同的方式创建连接:

代码语言:javascript
复制
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()

完整的示例就在这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70400302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档