Tinkerpop遍历转为字符串

huangapple go评论72阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年9月25日 23:58:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/64067558.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定