A Gremlin Query to Return a Results as a Tree?

179 views
Skip to first unread message

James Thornton

unread,
Jun 24, 2011, 6:33:27 PM6/24/11
to gremli...@googlegroups.com
I'm looking at ways to get Gremlin to return query results in tree form, such as returning all the nested comments for a Web page in one query. 

For example:

comment
comment
- comment
- - comment
- - - comment
comment
- comment

Is this a job for paths?

James Thornton

unread,
Jun 24, 2011, 9:38:54 PM6/24/11
to gremli...@googlegroups.com
Actually, using something like gather might be more appropriate...

comments = []
g.V.out.gather{comments << it}.loop....

...still playing with it though.

James Thornton

unread,
Jun 24, 2011, 11:47:41 PM6/24/11
to gremli...@googlegroups.com
closer...

g.v(1).out.sideEffect{ x = [it]; li.push(x) }.out.sideEffect{ x << [it] }

James Thornton

unread,
Jun 25, 2011, 2:16:17 AM6/25/11
to gremli...@googlegroups.com
Ok, here's what I have so far...

comments = []
 g.v(1).in('comment_on').sideEffect{ x = [it]; comments << x; next = true }.in('comment_on').sideEffect{ if (next == true) {  nest = []; x << nest; next = false; } ; nest << it }.loop(4){it.loops < 1000} >> -1 
return comments


However, Rexster returns this...

{"results":["[v[18], [v[30], v[21], v[24], v[27]]]"],"success":true,"version":"0.5-SNAPSHOT","queryTime":4.963128}

...notice that the value of the results list is a single string instead of list items.


Pierre De Wilde

unread,
Jun 25, 2011, 4:24:59 AM6/25/11
to gremli...@googlegroups.com
An issue has been created for the incorrect Rexster result.
Thanks for reporting,
Pierre

2011/6/25 James Thornton <james.t...@gmail.com>

stephen mallette

unread,
Jun 25, 2011, 5:36:43 AM6/25/11
to gremli...@googlegroups.com
I'm sure you both got the message update at this point from github
where I commented on the issue, but I'll just mention it here too.
The gremlin script engine is returning the result as a string, so from
Rexster's perspective I think it's doing what it is supposed to do.
Perhaps, Marko can provide some insight...

https://github.com/tinkerpop/rexster/issues/118

Best regards,

Stephen

James Thornton

unread,
Jun 25, 2011, 7:19:28 PM6/25/11
to gremli...@googlegroups.com
Is the right approach to writing a query like this, or is there a better way?

Is there a way to break up the query into multiple lines so it doesn't have to wrap in your editor?


Marko Rodriguez

unread,
Jun 25, 2011, 10:23:49 PM6/25/11
to gremli...@googlegroups.com

Hi James,

I'm on travel. I will get you an answer when I settle.

See you,
Marko

James Thornton

unread,
Jun 25, 2011, 10:36:50 PM6/25/11
to gremli...@googlegroups.com
Cool. Thanks, Marko!

Marko Rodriguez

unread,
Jun 25, 2011, 10:44:35 PM6/25/11
to gremli...@googlegroups.com
I'm thinking about your query and about making embedded lists based on where you are in the loop (it.loops) is where I'm thinking of going with this... but its sorta ugly... I may have to make a "tree path"-based pipe to make this pretty... perhaps I'm over traveled and not thinking correctly.....

...
..
.

Marko.

http://markorodriguez.com

On Jun 25, 2011, at 8:36 PM, James Thornton wrote:

> Cool. Thanks, Marko!

James Thornton

unread,
Jun 26, 2011, 2:47:08 AM6/26/11
to gremli...@googlegroups.com
Thanks for looking into that Stephen!
Reply all
Reply to author
Forward
0 new messages