Best way to travel a tree

24 views
Skip to first unread message

aab...@gradiant.org

unread,
Feb 4, 2020, 11:12:41 AM2/4/20
to JanusGraph users
Hello,

I'm currently working with janusgraph and I would like to know how is the best way or approach to travel a full tree graph. In this case I have all the information stored in a graph with a tree schema, and I would like to start from the root and travel the whole graph gathering all the data stored in its nodes, and saving it to the corresponding objects, depending on their node types.

The basic approach of getting the first round of nodes, recover it, get the data and from them build another traversals to travel to the next nodes... sounds inefficient to me.

Thanks in advance!

P.S: I'm building the query with gremlin in java.

Oleksandr Porunov

unread,
Feb 5, 2020, 12:20:49 AM2/5/20
to JanusGraph users
Hi,

I am a little bit confused with the question. I think such type of questions are better fit to the next group: https://groups.google.com/forum/#!forum/gremlin-users

Also, it would be much better if you could explain your use cases a little bit more. You just described a kind of BFS to traverse a tree. Well, depending on the use case it may be efficient or inefficient.

If you want to work with a tree, actual TinkerPop tree may be useful:
https://github.com/tinkerpop/gremlin/wiki/Tree-Pattern

Some docs:
http://tinkerpop.apache.org/docs/current/recipes/#tree

Possibly, if you are looking for partial tree, you may find this question to be useful:
https://stackoverflow.com/questions/47639418/get-partial-tree-of-a-gremlin-query

Best regards,
Oleksandr

aab...@gradiant.org

unread,
Feb 5, 2020, 11:23:46 AM2/5/20
to JanusGraph users
Hello Porunov,

First of all thank you very much for your response. I would like to give you more details to see if you can help me with this case.

I have a graph with all the data stored as follows:



As you can see in this image, you can see that I have a main node root, and from there we will have a tree structure with GROUPS - OUTLIERS. From a group can hang other groups or RESULT nodes, and the same for outliers. The results are the only nodes which we can be certain that will be a leaf node. So here we have an unknown size tree, and the point is to recover all this data and map it to a java object. (This graphs won't be really big, so storing them as a java object should not be an issue thinking in terms of memory).

Right now I'm exploring the tree() step to see if I can do something with it. How would you solve this situation?

Thanks in advance!

Cheers,
Adrian

marc.de...@gmail.com

unread,
Feb 6, 2020, 1:54:56 AM2/6/20
to JanusGraph users
Hi Adrian,

The Tree object returned by the tree() step has a limited API, but maybe it is just what you need.

An alternative is to use the subgraph() step. The resulting local Subgraph object can be queried using ordinary gremlin (so, an extensive API). I like this option best.

If you use JanusGraph embedded (so, without gremlin-server) you even can consider a specific tree, once queried, as "a local object" because Janusgraph will store all elements of that tree in its cache.

HTH,    Marc

Op woensdag 5 februari 2020 17:23:46 UTC+1 schreef aab...@gradiant.org:
Reply all
Reply to author
Forward
0 new messages