Group vertices together

31 views
Skip to first unread message

Fairuz WAN ISMAIL

unread,
Feb 1, 2015, 2:06:16 PM2/1/15
to gremli...@googlegroups.com
Hi,

I have a sample data like below and I'm having problems to vertices some nodes together. Draft, Ready and Published are status vertices, while the others are my data that I want to retrieve.

Instead of having an output of 7 vertices, I would like to have both Pan vertices and Cicero vertices grouped together. Notice that they are "similar" nodes but one are in published state and the other is in Ready/Draft state. So my idea is to have only one Pan (and only one Cicero) as the output but contain the information from the draft/ready state and published state.

I started to try with copySplit, and at each branch I do different queries to retrieve different cases of the graph. But still no idea on how to group the vertices together. Any suggestions are welcomed. Thanks


Regards,
Fairuz

Data:


Daniel Kuppitz

unread,
Feb 1, 2015, 5:58:29 PM2/1/15
to gremli...@googlegroups.com
Hi Fairuz,

I don't understand what kind of output you expect. Can you show an example? Like

gremlin> g.mysteriousTraversal()
==>here
==>comes
==>your
==>expectation

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/fdd59280-68b5-478e-8f2c-8603c48261c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Fairuz WAN ISMAIL

unread,
Feb 1, 2015, 7:15:46 PM2/1/15
to gremli...@googlegroups.com
Hi Daniel,

Sorry for confusing explaination. This what I might expect from the traversal (I don't even know if it's possible)

==> v[1]
==> [v[2], v[4]]
==> [v[3], v[5]]
==> v[6]
==> v[7]

I dont know what is possible with other than [v[2], v[4]], a new "thing" with both info of v[2] and v[4] is OK too.

Thanks,
Fairuz

Daniel Kuppitz

unread,
Feb 1, 2015, 8:50:16 PM2/1/15
to gremli...@googlegroups.com
Hey Fairuz,

you've mentioned copySplit, so I assume that you're using TP2. Here's the query:

g.V().has("type", "status").in("has-status").filter { !it.inE("has-draft").hasNext() }.ifThenElse {it.out("has-draft").hasNext()} {it.out("has-draft").path()} {it}

You can find the full test (and the TP3 version) here: https://gist.github.com/dkuppitz/81076dbbac3d69544dec

Cheers,
Daniel


Fairuz WAN ISMAIL

unread,
Feb 1, 2015, 11:13:45 PM2/1/15
to gremli...@googlegroups.com
Hi Daniel,

It works like a charm. Yes I still use TP2 since the client library that I'm using right now (Clojurewerkz Titanium and Ogre) depends on it. Right now I have additional work to convert this Gremlin expression into Clojure.

I already read about traversal patterns several time but never thinking of this kind of solution.

I see that the order of your output is exactly what I wanted. What I mean is v[7] and v[6] at the top of the list because they are never been published and v[1] at the end of the list because they are published and doesn't have any draft/ready content. Is this by accident? Or will it work like this every time.

Thanks,
Fairuz

Daniel Kuppitz

unread,
Feb 2, 2015, 8:29:44 AM2/2/15
to gremli...@googlegroups.com
It's more or less by accident (as you can see, TP3 already orders the result differently). If you don't specify an order, you can assume that the ordering you see is by accident - TP doesn't guarantee any specific default order.

Cheers,
Daniel


Reply all
Reply to author
Forward
0 new messages