【发布时间】:2019-08-11 15:41:43
【问题描述】:
是否可以从字节码生成 gremlin 脚本?
我正在开发一个 POC,我需要在其中通过 Gremlin API 查询图形 Azure CosmosDB 数据库。
目前,Azure CosmosDB 不支持字节码。 Azure 开发团队有started working on this,但目前尚未公布发布时间表。
我想准备工作代码,以便在将来普遍提供字节码支持时需要最少的重构。
基于Apache TinkerPop docs,提交Gremlin查询有两种方式:字节码和脚本
# script
client = Client('ws://localhost:8182/gremlin', 'g')
list = client.submit("g.V().has('person','name',name).out('knows')",{'name': 'marko'}).all()
# bytecode
g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
list = g.V().has("person","name","marko").out("knows").toList()
“字节码方式”在我看来效率更高(语法检查、IDE 智能感知等),而且我对创建 DSL(域特定语言)感兴趣。
是否可以使用fluent api并将其序列化为字符串,类似于以下方式:
client = Client('ws://localhost:8182/gremlin', 'g')
g = traversal()
q = g.V().has("person","name","marko").out("knows").toString()
list = client.submit(q).all()
我正在使用 python 3.5 和 gremlinpython 3.4.0
【问题讨论】:
-
还有gremlinpy 为您构建脚本(带有绑定参数)。我个人觉得(由于供应商对字节码的支持乏善可陈,例如 CosmosDB)如果你想使用 python,这条路线可能是更好的方法。
-
@Sascha 谢谢,我一定会试一试。我可能错了,但我认为编写翻译器会更有益,因为它使我有可能使用 GraphTraversal 扩展编写 DSL 并将字节码输出转换为 groovy 脚本。在某些时候,当字节码可用时,我将切换到字节码。不确定 gremlinpy 是否也可以做到这一点。
标签: python gremlin bytecode azure-cosmosdb-gremlinapi gremlinpython