orderBy and Limit or Rang steps ?

273 views
Skip to first unread message

Thomas A

unread,
Apr 7, 2015, 2:49:29 AM4/7/15
to gremli...@googlegroups.com
Hi,


I'm currently using Tinkerpop 3 with TitanDB in Java.

I got a picky situation.

I would like, after an orderBy step limit the number of value. And in second function, I would like to find the third element in a orderBy.
If I put a limit or a rang after the orderBy, I will act on nothing. Indeed, the next step send me back my result in a Map<Vertex, long>. If I put my limit or my rang before my orderBy, I will not select the correct vertex (I'm not sur for this one, i didn't yet do all tests).


g.V().[different filter steps].groupCount().cap().orderBy(T.value, Order.decr).next(); //Give an ordered result in a Map<Vertex, long>

g
.V().[different filter steps].groupCount().cap().orderBy(T.value, Order.decr).limit(100).next(); //Will do nothing
g
.V().[different filter steps].groupCount().cap().orderBy(T.value, Order.decr).rang(42).next(); //Will send an error


Have you an idea how to do ?
For the moment my graph is very little (14 nodes) but when it will be very big, the map element will be so huge ...

Thank you for your help,
Thomas
Message has been deleted

Thomas A

unread,
Apr 7, 2015, 3:26:12 AM4/7/15
to gremli...@googlegroups.com
I did tests to put the rang and the limitation step before the orderBy or the GroupCount(). Like expected, it didn't work like I want.
So it's still unclear how to do this.

Daniel Kuppitz

unread,
Apr 7, 2015, 4:00:23 AM4/7/15
to gremli...@googlegroups.com
It's not rang, it's either range(x, y) or limit(x). However, I think the main problem is that Titan still uses TP3 M6, which doesn't support .range(local, x, y), hence you'll need to use a Groovy function to limit the result:

traversal.next().take(3)

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/0ca6f2f0-7705-4c5a-86be-972117d4722d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas A

unread,
Apr 7, 2015, 4:12:36 AM4/7/15
to gremli...@googlegroups.com
Thank you for your help !


Just for next reader, the gremlin compilation method changed in Tinkerpop 3. It is necessary to use the object :
ScriptEngine engine = new GremlinGroovyScriptEngine();

Thomas A

unread,
Apr 12, 2015, 9:23:59 AM4/12/15
to gremli...@googlegroups.com
I come back to you.

I didn't really solved my issue with range(int, int) and limit().

I'm able to limit the size of the hashmap at the end by the operation:
traversal[filtring step].groupCount().cap().next().take(3)
My concern is to be able to limit the memory usage. I'm worry by the production of the Hashmap. Indeed, I read this like : applied your filter, count group, produce the hashmap and then limit it size. If Gremlin work like this, the output of the next() step will be very huge. So how work Gremlin for this case ?

My second issue is still with the range(int, int)-step. If I want the 1 000 000-th value of the group count, then I don't want produce all the hashmap to keep only one value. Gremlin has no method to do that ? If not, I will search another way but I have no clue how to do it for the moment.

Best regards,
Thomas

Daniel Kuppitz

unread,
Apr 12, 2015, 10:20:08 AM4/12/15
to gremli...@googlegroups.com
It has to be like that. Since you don't know the counts prior the execution, you cannot limit the number of HashMap entries.

Cheers,
Daniel

Thomas A

unread,
Apr 12, 2015, 11:25:44 AM4/12/15
to gremli...@googlegroups.com
That right. That make sense.
I will probably play with subgraph to limit the research.
Reply all
Reply to author
Forward
0 new messages