pieter martin created TINKERPOP3-924:
----------------------------------------
Summary: Have an easier way to select full subgraphs/paths/trees
Key: TINKERPOP3-924
URL: https://issues.apache.org/jira/browse/TINKERPOP3-924
Project: TinkerPop 3
Issue Type: Improvement
Components: process
Affects Versions: 3.1.0-incubating
Reporter: pieter martin
Assignee: Marko A. Rodriguez
This issue follows on after some discussion on the gremlin users [mailing list
| https://groups.google.com/forum/#!topic/gremlin-users/wziSPqeMxLg] where
[~dkuppitz] has provided help.
The requirement is to query a full subgraph from the graph. By full subgraph I
mean that every element touched along the path is returned and not just the
leaf elements at the n'th degree as is standard.
The need to lift complete subgraphs is I think very common. Think of any tree
structure, code or ui. It generally has leaf nodes at all sorts of depths.
The other, is for any OGM tool to be able to eagerly hydrate an object graph
with one gremlin query (optimized). This is something that if its supported
greatly improves the usability and performance of the ORM tool.
So at the ORM level or at pure gremlin its common usecase.
Gremlin can do the above but not well. This requirement seeks an easier manner
in which to return all friends and their addresses, in particular including
friends that have no address.
There is currently 2 ways in which gremlin already does return the full tree.
As an simple example consider the following.
{noformat}
John--friend-->Peter--address-->NewYork
--friend-->Joe
--address-->Boston
{noformat}
I am looking for the full tree of john's friends and their addresses.
It should return,
{noformat}
{John={Peter={NewYork}, Joe}}
{noformat}
h2. gremlin 1
{noformat}
g.V(person1).emit().repeat(out("friend", "address")).times(2).tree()
{noformat}
returns,
{noformat}
{John={Boston, Peter={NewYork}, Joe}}
{noformat}
This pattern is almost right but because "friend" and "address" is always
traversed it returns John's address which is wrong for this use-case.
This pattern is generally weak as just repeating all labels x times is
inaccurate and fault prone and just plane semantically not what is required.
The requirement is to specify the path exactly.
h2. gremlin 2
{noformat}
g.V(john).choose(
__.out("friend"), __.out("friend").choose(
__.out("address"), __.out("address"), __.identity()
), __.identity()
).tree()
{noformat}
returns,
{noformat}
{John={Peter={NewYork}, Joe}}
{noformat}
This is correct and the path is specified exactly.
But alas its a pain to construct, reads difficult and, at least in sqlg's case,
very difficult to optimize.
What I propose is direct support for returning a complete sub-graph. Something
like, (only thinking about readability, not implementation here)
{noformat}
g.V(person1).emit(out("friend").out("address")).tree()
or
g.V(person1).emit().out("friend").out("address").tree()
or
g.V(person1).out("friend").out("address").fullTree()
or
g.V(person1).out("friend").out("address").completeTree()
or
g.V(person1).out("friend").out("address").subGraph()
{noformat}
Thanks
Pieter
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)