Is it possible to generate gremlin queries from bytecode in python

Seb*_*idz 6 python bytecode gremlin azure-cosmosdb-gremlinapi gremlinpython

Is it possible to generate gremlin script from the bytecode?

I am working on a POC in which I need to query graph Azure CosmosDB database via Gremlin API.

Currently, Azure CosmosDB does not support bytecode. Azure development team has started working on this but no release timeline has been published so far.

I would like to prepare working code which would require minimum refactoring in future when bytecode support will be generally available.

Based on the Apache TinkerPop docs, there are two ways of submitting Gremlin queries: bytecode and script

# 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()
Run Code Online (Sandbox Code Playgroud)

The "bytecode way" seems to me much more efficient (syntax checking, IDE intellisens, etc.) moreover I am interested in creating the DSL (Domain Specific Language).

Would it be possible to use the fluent api and serialize it to string, in a way similar to this:

client = Client('ws://localhost:8182/gremlin', 'g')
g = traversal()
q = g.V().has("person","name","marko").out("knows").toString()
list = client.submit(q).all()
Run Code Online (Sandbox Code Playgroud)

I am using python 3.5 and gremlinpython 3.4.0

ste*_*tte 2

绝对可以从字节码生成遍历的字符串表示形式。TinkerPop 已经为 Groovy 和 Python 脚本做到了这一点(出于各种原因,主要是为了测试,但它还有其他用途,例如支持字节码中的 lambda 和其他实用目的)。我们通过ScriptTranslator实现来实现这一目标,其中一个用于Groovy,两个用于Python(其中一个实际上用于Jython)。当然,问题是所有这些ScriptTranslator实例在技术上都是针对 JVM 的,听起来您需要一些针对本机 Python 的东西。

也许您可以检查PythonTranslator代码并在本机 Python 中实现它?它基本上只是一堆if-then和 字符串连接。