Reputation: 2146
I'm trying to get all the unknown vertices that are connected to a known vertex by an edge using C# Datastax CassandraCSharpDriver.Graph code.
This gremlin code correctly returns the list of unknown vertices as well as the target known vertex:
g.V().has("mything","key", "mykey")
.emit()
.repeat(outE("contains").inV()).valueMap(true)
I tried a traversal like this in C# but it doesn't come back, I think the repeat is infinite (or very slow):
g.V()
.Has("mything", "key", "mykey")
.Emit()
.Repeat(g.V()
.Has("mything", "key", "mykey")
.OutE("contains").InV())
I'm trying a traversal like this in C#, but the compiler won't accept '("query")', so I'm not sure how to put the traversal in the Repeat clause:
g.V()
.Has("mything", "key", "mykey")
.As("query").Emit()
.Repeat(("query").OutE("contains").InV())
What's the trick to the Repeat clause? Or is there a better way to get all the unknown vertices connected to a known vertex in C#?
Upvotes: 0
Views: 83
Reputation: 712
I think you're looking for the anonymous graph traversal class Gremlin.Net.Process.Traversal.__
:
var graphResultSet = await session.ExecuteGraphAsync(g.V()
.Has("mything", "key", "mykey").Emit()
.Repeat(__.OutE("contains").InV())).ConfigureAwait(false);
I've ran a simple code snippet with this query (shown below) and I get this console output:
[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]
Code snippet:
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}]")));
Upvotes: 1