使用 C# Datastax CassandraCSharpDriver.Graph 获取连接到已知顶点的所有未知顶点
Get all unknown vertices connected to a known vertex with C# Datastax CassandraCSharpDriver.Graph
我正在尝试使用 C# Datastax CassandraCSharpDriver.Graph 代码获取通过边连接到已知顶点的所有未知顶点。
这个 gremlin 代码正确 returns 未知顶点列表以及目标已知顶点:
g.V().has("mything","key", "mykey")
.emit()
.repeat(outE("contains").inV()).valueMap(true)
我在 C# 中尝试过这样的遍历,但它没有返回,我认为重复是无限的(或非常慢):
g.V()
.Has("mything", "key", "mykey")
.Emit()
.Repeat(g.V()
.Has("mything", "key", "mykey")
.OutE("contains").InV())
我正在 C# 中尝试这样的遍历,但编译器不接受“("query")”,所以我不确定如何将遍历放在 Repeat 子句中:
g.V()
.Has("mything", "key", "mykey")
.As("query").Emit()
.Repeat(("query").OutE("contains").InV())
Repeat 子句有什么诀窍?或者有没有更好的方法让所有未知顶点连接到 C# 中的已知顶点?
我认为您正在寻找匿名图遍历 class Gremlin.Net.Process.Traversal.__
:
var graphResultSet = await session.ExecuteGraphAsync(g.V()
.Has("mything", "key", "mykey").Emit()
.Repeat(__.OutE("contains").InV())).ConfigureAwait(false);
我已经 运行 了一个包含此查询的简单代码片段(如下所示),并且我得到了以下控制台输出:
[label: mything; key: mykey]
[label: mything1; key: mykey15]
[label: mything1; key: mykey12]
[label: mything; key: mykey]
[label: mything1; key: mykey17]
[label: mything1; key: mykey16]
[label: mything1; key: mykey14]
[label: mything1; key: mykey13]
[label: mything1; key: mykey1]
代码片段:
session.ExecuteGraph(new SimpleGraphStatement(
"schema.propertyKey('key').Text().ifNotExists().create();" +
"schema.edgeLabel('contains').multiple().ifNotExists().create();" +
"schema.vertexLabel('mything').properties('key').ifNotExists().create();" +
"schema.vertexLabel('mything1').properties('key').ifNotExists().create();" +
"schema.edgeLabel('contains').connection('mything', 'mything1').add();"));
var g = DseGraph.Traversal(session);
await session.ExecuteGraphAsync(g
.AddV("mything").Property("key", "mykey").As("cp")
.AddV("mything").Property("key", "mykey").As("cp1")
.AddV("mything1").Property("key", "mykey1").As("cl")
.AddV("mything1").Property("key", "mykey12").As("cl1")
.AddV("mything1").Property("key", "mykey13").As("cl2")
.AddV("mything1").Property("key", "mykey14").As("cl3")
.AddV("mything1").Property("key", "mykey15").As("cl4")
.AddV("mything1").Property("key", "mykey16").As("cl5")
.AddV("mything1").Property("key", "mykey17").As("cl6")
.AddE("contains").From("cp").To("cl")
.AddE("contains").From("cp1").To("cl1")
.AddE("contains").From("cp").To("cl2")
.AddE("contains").From("cp").To("cl3")
.AddE("contains").From("cp1").To("cl4")
.AddE("contains").From("cp").To("cl5")
.AddE("contains").From("cp").To("cl6"))
.ConfigureAwait(false);
var graphResultSet = await session.ExecuteGraphAsync(g.V()
.Has("mything", "key", "mykey").Emit()
.Repeat(__.OutE("contains").InV())).ConfigureAwait(false);
var vertices = graphResultSet.Select(elem => elem.To<Vertex>()).ToList();
Console.WriteLine(
string.Join(
Environment.NewLine,
vertices.Select(v => $"[label: {v.Label}; key: {v.GetProperty("key").Value}]")));
我正在尝试使用 C# Datastax CassandraCSharpDriver.Graph 代码获取通过边连接到已知顶点的所有未知顶点。
这个 gremlin 代码正确 returns 未知顶点列表以及目标已知顶点:
g.V().has("mything","key", "mykey")
.emit()
.repeat(outE("contains").inV()).valueMap(true)
我在 C# 中尝试过这样的遍历,但它没有返回,我认为重复是无限的(或非常慢):
g.V()
.Has("mything", "key", "mykey")
.Emit()
.Repeat(g.V()
.Has("mything", "key", "mykey")
.OutE("contains").InV())
我正在 C# 中尝试这样的遍历,但编译器不接受“("query")”,所以我不确定如何将遍历放在 Repeat 子句中:
g.V()
.Has("mything", "key", "mykey")
.As("query").Emit()
.Repeat(("query").OutE("contains").InV())
Repeat 子句有什么诀窍?或者有没有更好的方法让所有未知顶点连接到 C# 中的已知顶点?
我认为您正在寻找匿名图遍历 class Gremlin.Net.Process.Traversal.__
:
var graphResultSet = await session.ExecuteGraphAsync(g.V()
.Has("mything", "key", "mykey").Emit()
.Repeat(__.OutE("contains").InV())).ConfigureAwait(false);
我已经 运行 了一个包含此查询的简单代码片段(如下所示),并且我得到了以下控制台输出:
[label: mything; key: mykey]
[label: mything1; key: mykey15]
[label: mything1; key: mykey12]
[label: mything; key: mykey]
[label: mything1; key: mykey17]
[label: mything1; key: mykey16]
[label: mything1; key: mykey14]
[label: mything1; key: mykey13]
[label: mything1; key: mykey1]
代码片段:
session.ExecuteGraph(new SimpleGraphStatement(
"schema.propertyKey('key').Text().ifNotExists().create();" +
"schema.edgeLabel('contains').multiple().ifNotExists().create();" +
"schema.vertexLabel('mything').properties('key').ifNotExists().create();" +
"schema.vertexLabel('mything1').properties('key').ifNotExists().create();" +
"schema.edgeLabel('contains').connection('mything', 'mything1').add();"));
var g = DseGraph.Traversal(session);
await session.ExecuteGraphAsync(g
.AddV("mything").Property("key", "mykey").As("cp")
.AddV("mything").Property("key", "mykey").As("cp1")
.AddV("mything1").Property("key", "mykey1").As("cl")
.AddV("mything1").Property("key", "mykey12").As("cl1")
.AddV("mything1").Property("key", "mykey13").As("cl2")
.AddV("mything1").Property("key", "mykey14").As("cl3")
.AddV("mything1").Property("key", "mykey15").As("cl4")
.AddV("mything1").Property("key", "mykey16").As("cl5")
.AddV("mything1").Property("key", "mykey17").As("cl6")
.AddE("contains").From("cp").To("cl")
.AddE("contains").From("cp1").To("cl1")
.AddE("contains").From("cp").To("cl2")
.AddE("contains").From("cp").To("cl3")
.AddE("contains").From("cp1").To("cl4")
.AddE("contains").From("cp").To("cl5")
.AddE("contains").From("cp").To("cl6"))
.ConfigureAwait(false);
var graphResultSet = await session.ExecuteGraphAsync(g.V()
.Has("mything", "key", "mykey").Emit()
.Repeat(__.OutE("contains").InV())).ConfigureAwait(false);
var vertices = graphResultSet.Select(elem => elem.To<Vertex>()).ToList();
Console.WriteLine(
string.Join(
Environment.NewLine,
vertices.Select(v => $"[label: {v.Label}; key: {v.GetProperty("key").Value}]")));