英文:
Embedded gremlin server via gremlin-go library in golang
问题
我是你的中文翻译助手,以下是翻译好的内容:
我刚开始学习Golang,需要找到一个类似于org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph的东西,以便在不连接到图数据库的情况下使用gremlin方法来遍历嵌入式图。
我找到了gremlin-go (github.com/apache/tinkerpop/gremlin-go/v3/driver),它符合我的需求,只是它需要连接到gremlin服务器。是否有办法在不连接到服务器的情况下初始化GraphTraversalSource,就像Java版本中通过以下代码实现的那样?
Graph graph = TinkerGraph.open();
GraphTraversalSource g = traversal().withEmbedded(graph);
我尝试了以下代码:
package main
import (
"fmt"
gremlingo "github.com/apache/tinkerpop/gremlin-go/v3/driver"
)
func main() {
graph := gremlingo.Graph{}
gts := gremlingo.NewGraphTraversalSource(&graph, nil, gremlingo.ReadOnlyStrategy())
prop := &gremlingo.GremlinType{"java.lang.Object"}
gts.AddV("type_test").Property("data", prop).Iterate()
cnt, _ := gts.V().Count().ToList()
val, _ := cnt[0].GetInt32()
fmt.Println(val)
}
但是得到了数组越界异常,意味着没有添加任何顶点。是否有办法在本地创建图,然后遍历它?
英文:
I'm new to Golang and need to find an analog to org.apache.tinkerpop.gremlin.tinkergraph.structure. TinkerGraph to use gremlin methods for traversing embedded graphs without connection to graph database.
I've found gremlin-go (github.com/apache/tinkerpop/gremlin-go/v3/driver), that suites my needs, except the fact that it needs connection to gremlin server. Is there any way to initialize GraphTraversalSource without connection to server, like it is done in Java version via this code?
Graph graph = TinkerGraph.open();
GraphTraversalSource g = traversal().withEmbedded(graph);
I've tried the following:
package main
import (
"fmt"
gremlingo "github.com/apache/tinkerpop/gremlin-go/v3/driver"
)
func main() {
graph := gremlingo.Graph{}
gts := gremlingo.NewGraphTraversalSource(&graph, nil, gremlingo.ReadOnlyStrategy())
prop := &gremlingo.GremlinType{"java.lang.Object"}
gts.AddV("type_test").Property("data", prop).Iterate()
cnt, _ := gts.V().Count().ToList()
val, _ := cnt[0].GetInt32()
fmt.Println(val)
}
But get out of bounds exception, meaning, that no vertices had been added. Is there any way to create graph locally and then traverse it?
答案1
得分: 1
不,这是不可能的。gremlin-go
不是Gremlin查询处理引擎的实现,也不像Java那样公开接口以实现图数据库。与所有非JVM基础的Gremlin实现一样,它将处理任务委托给具备这些能力的Gremlin Server。
英文:
No - this is not possible. gremlin-go
is not an implementation of the Gremlin query processing engine nor does it expose interfaces as Java does to even implement a graph database. Like all the non-JVM based Gremlin implementations, it delegates that processing to Gremlin Server which has those capabilties.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论