英文:
Tinkerpop traversal to string
问题
从遍历中获取一个准备好供使用的Gremlin请求是否可能?就像JPA在调试级别记录日志一样。对于TinkerPop来说,调试输出会给出traversal.toString()
,但是将其转换为请求很耗时。
英文:
Is it possible to get from a traversal a gremlin request ready to use ? As JPA do with the log in debug level. For tinkerpop the debug give the traversal.toString()
which is time consuming to transform in a request.
答案1
得分: 3
你可以使用 Apache TinkerPop 中的 GroovyTranslator 类将遍历转换回文本形式。
如果你有一个定义如下的遍历:
Traversal t =
g.V().has("airport","region","US-TX").
local(values("code","city")).
fold();
你可以使用以下代码将其转换为文本字符串:
String query;
query = GroovyTranslator.of("g").
translate(t.asAdmin().getBytecode());
System.out.println("\nResults from GroovyTranslator on a traversal");
System.out.println(query);
这里还有更多的示例:
https://github.com/krlawrence/graph/blob/master/sample-code/RemoteWriteText.java
英文:
You can translate a traversal back into a textual form using the GroovyTranslator class from Apache TinkerPop.
If you had a traversal defined as follows
Traversal t =
g.V().has("airport","region","US-TX").
local(values("code","city").
fold());
You can convert that back to a text string using
String query;
query = GroovyTranslator.of("g").
translate(t.asAdmin().getBytecode());
System.out.println("\nResults from GroovyTranslator on a traversal");
System.out.println(query);
There are further examples here:
https://github.com/krlawrence/graph/blob/master/sample-code/RemoteWriteText.java
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论