Cayley 0.7.0 depth function issue


#1

Hi Guys

I am facing some strange behavior of the depth function. Please help me out asap if I am missing something.
Example : I am working on the below scenario -

Test1 RunsOn Test2
Test2 RunsOn Test3
Test3 DependsOn Test4
Test4 DependsOn Test5
Test5 BelongsTo Test6
Test6 Contains Test7
Test4 ConnectedTo Test8
Test5 ConnectedTo Test9

I am using the below query to find the depth for the node Test2 by passing depth = 3. As per the depth function it should show three step up & 3 step down nodes.

So, the result should be the below 6 nodes .
Test1, Tes2,Test3, Tes4, Test5,Test8

But I am getting 8 nodes instead of 6 nodes.
Test1, Test2, Test3,Test4, Test5, Test8, Test6, Test9

Query :

var path = g.M().Both();
var depth = 3;
g.V(“Test2”).FollowRecursive(path,depth).ForEach( function(v){
g.V(v.id).OutPredicates().ForEach( function®{
g.V(v.id).Out().ForEach( function(t){
var node = {
source: v.id,
relation : r.id,
target: t.id
}
g.Emit(node)
})
})
})

Thanks in advance.


#2

Isn’t test5 at depth three? And then you start a new path out from there and get 6 and 9


#3

Hi @Jorgen

Thanks for the quick response.

Yeah Test5 is at the depth 3 but why I am getting Test6 & Test9 because as I am calculating from Test2 and I am not starting any new path from Test5 as per the query.So, If i’ll break the depth of my query then it should be come as below :
Depth 1st : Test3
Depth 2nd : Test4
Depth 3rd : Test5 & Test8


#4

I’m on my phone in public transport so it’s a bit hard to type a good response, but you do start a new path with g.v(second id).Out. v.id is probably 5 and then you start from 5 out and you end up at 9 and six.
The depth for follow recursive only counts in that path.


#5

Hi @Jorgen

Thanks but I didn’t get you.

I want to exclude this Test6 & Test9 as it should not be the part of Depth 3. If you will pass depth =4 then only these two nodes should come into action.


#6

Hi @amritsingh

Can you please help me out with this as earlier you have helped me with the depth function syntax but at that time i was using the 0.6.1 version.

Thanks in advance.


#7

I tried to build this example in go and run into another issue. I discussed this with @dennwc
He will need to look into it at a later time.

I tried to get this to work, but I’ve the same problem.
I believed something like this would do the trick:

// Go code
path := cayley.StartMorphism().BothWithTags([]string{“relation”}).Tag(“node”)
p := cayley.StartPath(store, from).Tag(“source”).FollowRecursive(path, 3, []string{“d”})

But this results in 1 3 2 4 5 and not in 1 3 2 4 5 8

This might be a bug. To be continued.


#8

Hi @Jorgen

I have a update for you. In a separate window I have discussed about the query with @dennwc and he helped me to correct it.

Now, the correct one is as below :

var path = g.M().Both();
var depth = 3;
g.V(“Test2”).FollowRecursive(path,depth).ForEach( function(v){
g.V(v.id).OutPredicates().ForEach( function®{
g.V(v.id).Out(r.id).ForEach( function(t){
var node = {
source: v.id,
relation : r.id,
target: t.id
}
g.Emit(node)
})
})
})

Now, continued to this question I am getting the result as per the depth = 3 for Test2 node as below.

{
“result”: [
{
“relation”: “RunsOn”,
“source”: “Test1”,
“target”: “Test2”
},
{
“relation”: “DependsOn”,
“source”: “Test3”,
“target”: “Test4”
},
{
“relation”: “RunsOn”,
“source”: “Test2”,
“target”: “Test3”
},
{
“relation”: “DependsOn”,
“source”: “Test4”,
“target”: “Test5”
},
{
“relation”: “ConnectedTo”,
“source”: “Test4”,
“target”: “Test8”
},
{
“relation”: “BelongsTo”,
“source”: “Test5”,
“target”: “Test6”
},
{
“relation”: “ConnectedTo”,
“source”: “Test5”,
“target”: “Test9”
}
]
}

Now, as per the diagram hierarchy We need to exclude two results(Test6 & Test9) from the output.

Thanks in advance.


#9

@Chaitanya Test6 and Test9 are actually results from g.V(v.id).Out(r.id) jump.

Try to list all nodes from your query to see want it returns before emitting nodes:

g.V("Test2").FollowRecursive(path,depth).All()

This will print results similar to @Jorgen’s, so it includes node Test5 for exmplae, and then you run g.V(v.id).Out(r.id).ForEach( that will jump from Node5 to anything that has that relation (nodes Test6 and Test9).

The real problem as @Jorgen sescribed is that it skips Test8 for some reason, although it has a correct depth.

Try tagging predicates and targets directly instead of re-running the query:

var path = g.M().Both(nil, "relation").Tag("target");

#10

Hi @dennwc

Thanks for the explanation.

But it is not skipping Test8 for me, It is there in the response. Only thing is, it is showing two extra nodes(Test6 & Test9).


#11

Hi @Jorgen & @dennwc

If I am trying from Test2 for depth=1, It should give me two nodes as result but it is giving one node as below :


#12

Maybe this is helpful

var path = g.M().Tag('hop').Both(null, "relation");
var depth = 5;
g.V("Test 2").Tag("source").FollowRecursive(path,depth).Tag("target").ForEach(function(v){
  var node = {
  source: v.hop,
  start: v.source,
  relation : v.relation,
  target: v.target
  }
  g.Emit(node)
})

This has the same issue with depth=1 (only resolves in Test 1), not sure what causes that. Maybe @dennwc has a clue. Not sure if this is a bug.

Depth 2 shows a line Test 1, 2 and 3


#13

Hi @Jorgen

I am getting null response for this query. PFA


#14

please note that I use Test 2, with a space. You need to remove the space


#15

Ohhh my bad @Jorgen , Sorry !!

But still i m not getting proper result. I have tried below scenario, it should show 5 nodes :frowning_face:

Query :

var path = g.M().Tag(‘hop’).Both(null, “relation”);
var depth = 2;
g.V(“Test3”).Tag(“source”).FollowRecursive(path,depth).Tag(“target”).ForEach(function(v){
var node = {
source: v.hop,
start: v.source,
relation : v.relation,
target: v.target
}
g.Emit(node)
})

Response :
{
“result”: [
{
“relation”: “RunsOn”,
“source”: “Test3”,
“start”: “Test3”,
“target”: “Test2”
},
{
“relation”: “DependsOn”,
“source”: “Test3”,
“start”: “Test3”,
“target”: “Test4”
},
{
“relation”: “RunsOn”,
“source”: “Test2”,
“start”: “Test3”,
“target”: “Test1”
}
]
}


#16

I believe you found a bug here. When I search the whole graph in Go I get this as a result:

"Test 2" => "Test 1"  depth: 1
"Test 2" => "Test 3"  depth: 1
"Test 3" => "Test 2"  depth: 2
"Test 3" => "Test 4"  depth: 2
"Test 4" => "Test 5"  depth: 3
"Test 4" => "Test 8"  depth: 3
"Test 5" => "Test 6"  depth: 4
"Test 5" => "Test 9"  depth: 4
"Test 6" => "Test 7"  depth: 5

But when I limit the depth to 2 I only get:

"Test 2" => "Test 1"  depth: 1
"Test 2" => "Test 3"  depth: 1
"Test 3" => "Test 2"  depth: 2

So here I miss:

"Test 3" => "Test 4" depth: 2


#17

I created an issue for this situation:

I believe that this is also the cause for node Test 8 not being returned because it does not select Test 4 on depth 2. The same for going into depth 3 not seeing node Test 8


#18

Thanks @Jorgen

But for depth=1 also not giving the proper result.

For Test3 by passing depth=1, it should give 2 nodes but it is resulting as 1 node only.

Response :

{
“result”: [
{
“relation”: “RunsOn”,
“source”: “Test3”,
“start”: “Test3”,
“target”: “Test2”
}
]
}


#19

Yes, it does this at every depth. I added that as a comment on the Issue.


#21

Found an issue and fixed it upstream.

v0.7.1 will be released in two weeks with this fix. If you want to try it earlier, you can compile from sources.