FollowRecursive parent


#1

Using http://blog.juganaru.eu/2016/06/28/google-cayley-graph-database-tutorial-family-tree/ as an example,

If I want all of John’s children and their children, I can write

g.V(‘john’).FollowRecursive(g.M().Out(‘child’)).All();

However, in the result set, I would like to know who the parent is as traversed by the FollowRecursive call / not both of childX’s parents as defined in the dataset / graph.

How can I get this?


FollowRecursive is not a function
#2

The most intuitive way would be to Tag a node before Out(child), so at the end of traversal last node’s parent will remain. But it will add a significant overhead in case of deep traversal, so it might be better to SaveR('child','parent') at the end of whole query.


#3

As you mentioned, I can get the parents via

g.V(‘john’).FollowRecursive(g.M().Out(‘child’)).SaveR(‘child’, ‘parent’).All()

but then I get all parents vs only the one that FollowRecursive traversed through… can you please provide query with the tag suggestion? I can’t seem to get that working…

g.V(‘john’).Follow(g.M().Tag(‘name’).Out(‘child’)).All() will tag the name of the current node, but

g.V(‘john’).FollowRecursive(g.M().Tag(‘name’).Out(‘child’)).All() drops it.

Also, to your point regarding deep traversal, I take it there is no option to specify the recursion depth as part of the FollowRecursive call?


#4

I assumed there will be only one child relation to a specific object. This suggests that you have multiple ones. This query will not work then.

This was a bug - recursive iterator was not tagging path correctly. Fixed upstream.

It’s not exposed to Gizmo queries yet. I’ll make this change a bit later. Can you file an issue on Github to track progress?


#5

Similar to the Tag bug, I think there is a related one to Save.

If I use this data set:

“x” “name” “xName” .
“x” “status” “ok” .
“y” “name” “yName” .
“y” “status” “ok” .
“1” “name” “A” .
“2” “name” “B” .
“3” “name” “C” .
“1” “relatesTo” “x” .
“2” “relatesTo” “x” .
“3” “relatesTo” “y” .
“1” “knows” “2” .
“2” “knows” “3” .
“2” “knows” “1” .

and run this query

g.V(‘1’).FollowRecursive(g.M().Tag(‘pid’).Save(‘name’, ‘pName’).Out(‘knows’), 2).Tag(‘cid’).Save(‘name’, ‘cName’).Out(‘relatesTo’).Has(‘status’, ‘ok’).Save(‘name’).All();

I get

{
	"result": [
		{
			"cName": "A",
			"cid": "1",
			"id": "x",
			"name": "xName",
			"pName": "B",
			"pid": "2"
		},
		{
			"cName": "B",
			"cid": "2",
			"id": "x",
			"name": "xName",
			"pName": "B",
			"pid": "2"
		},
		{
			"cName": "C",
			"cid": "3",
			"id": "y",
			"name": "yName",
			"pName": "B",
			"pid": "2"
		}
	]
}

but when I remove the Save from the morphism, ie

g.V(‘1’).FollowRecursive(g.M().Tag(‘pid’).Out(‘knows’), 2).Tag(‘cid’).Save(‘name’, ‘cName’).Out(‘relatesTo’).Has(‘status’, ‘ok’).Save(‘name’).All();

I get

{
	"result": [
		{
			"cName": "B",
			"cid": "2",
			"id": "x",
			"name": "xName",
			"pid": "1"
		},
		{
			"cName": "C",
			"cid": "3",
			"id": "y",
			"name": "yName",
			"pid": "2"
		},
		{
			"cName": "A",
			"cid": "1",
			"id": "x",
			"name": "xName",
			"pid": "2"
		}
	]
}

Notice how 2 / B’s pid is 2 in the first query and 1 in the second?

From my perspective, the correct result is the second / when Save is removed. I don’t see how 2/B can have a pid (parent id) of 2 as per the data set or why it would change depending on whether or not name was saved.


#6

Opened an issue to track progress: https://github.com/cayleygraph/cayley/issues/714 . Haven’t tried to reproducte it yet.