Re: [Neo4j] Gremlin - how to flatten a tree, and sort
hi Michael/Peter Peter: yes, that about sums it up. Webadmin console is fine, but REST not so much. Michael: my final set is a little over 100K nodes, and while I am still playing around as part of a technical proof of concept, I think I will need this data more or less in its entirety. I pumped up the memory settings in the neo configs, and increased my rest timeout, and managed to get a successful response (at which point my consuming code died, I think at the deserializing point :) ), so then I tried some manual chunking (using paged results), which worked pretty well, so I think that is the route I'll need to take. Also noteworthy, I have been using Tatham and Romiko's Neo4jClient stuff so far, and was just chatting via email to Romiko earlier, and he said that their client does support chunking already (at least in parts?) - so I will get latest and see what I can see. I think my main concern or question left is around the memory usage of my java.exe process: although everything now executes, its still not terribly fast (although considering its over REST, and is doing a lot of deserializing etc, I think its acceptable). Most importantly though, I see my java.exe process still consumes a lot of memory (half an hour later, and its still sitting at a gig...) - should I be worried about this? -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3499114.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Hi there, I wanted to look into more efficient ways to send back big responses, but had not time. Basically, throwing in more memory is what you have to do right now, or get Cypher or Gremlin to return more effective representations like only the properties you need, which cuts down the amount of data sent over the wire dramatically, plus chunking, see http://docs.neo4j.org/chunked/snapshot/query-skip.html Would that be a possibility Cheers, /peter neubauer GTalk: neubauer.peter Skype peter.neubauer Phone +46 704 106975 LinkedIn http://www.linkedin.com/in/neubauer Twitter http://twitter.com/peterneubauer http://www.neo4j.org - NOSQL for the Enterprise. http://startupbootcamp.org/ - Öresund - Innovation happens HERE. On Fri, Nov 11, 2011 at 9:35 AM, Kevin Versfeld kevin.versf...@gmail.com wrote: hi Michael/Peter Peter: yes, that about sums it up. Webadmin console is fine, but REST not so much. Michael: my final set is a little over 100K nodes, and while I am still playing around as part of a technical proof of concept, I think I will need this data more or less in its entirety. I pumped up the memory settings in the neo configs, and increased my rest timeout, and managed to get a successful response (at which point my consuming code died, I think at the deserializing point :) ), so then I tried some manual chunking (using paged results), which worked pretty well, so I think that is the route I'll need to take. Also noteworthy, I have been using Tatham and Romiko's Neo4jClient stuff so far, and was just chatting via email to Romiko earlier, and he said that their client does support chunking already (at least in parts?) - so I will get latest and see what I can see. I think my main concern or question left is around the memory usage of my java.exe process: although everything now executes, its still not terribly fast (although considering its over REST, and is doing a lot of deserializing etc, I think its acceptable). Most importantly though, I see my java.exe process still consumes a lot of memory (half an hour later, and its still sitting at a gig...) - should I be worried about this? -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3499114.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
hi again I've been trying that query out (slightly modified now to return all nodes of a different kind, but attached to a node in the first set), on a data set of around 100K, and I'm getting an OutOfMemoryError: { message : GC overhead limit exceeded, exception : java.lang.OutOfMemoryError: GC overhead limit exceeded, stacktrace : [ ] } My request (for gremlin over REST) is: script: m = [:]; g.v(id).in('R_PartOf').loop(1){m.put(it.object, it.loops); true} -1; m.sort{a,b - a.value = b.value}.keySet()._().in('R_OtherEdge'), params: { id: 284 } Any thoughts? -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3496857.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Hi, I've been trying that query out (slightly modified now to return all nodes of a different kind, but attached to a node in the first set), on a data set of around 100K, and I'm getting an OutOfMemoryError: { message : GC overhead limit exceeded, exception : java.lang.OutOfMemoryError: GC overhead limit exceeded, stacktrace : [ ] } My request (for gremlin over REST) is: script: m = [:]; g.v(id).in('R_PartOf').loop(1){m.put(it.object, it.loops); true} -1; m.sort{a,b - a.value = b.value}.keySet()._().in('R_OtherEdge'), params: { id: 284 } You have the following data structures consuming memory: 1. m 2. m sorted 3. the keyset of m Perhaps those are sufficiently large to blow our your memory. Perhaps test by, for example, not getting keySet or not sorting. When I do large Map-based computations in Gremlin, I use JDBM2 as my map data structure as its persistent and when it overflows memory, its written to disk. http://code.google.com/p/jdbm2/ HTH, Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
hi, thanks for the quick reply. I need to add some more info (some I left out, some I discovered later) This only happens when I use that gremlin over REST. Executing the gremlin in the webadmin console is pretty quick, and I don't see any memory spikes or anything. What I did (after posting the previous question) was to increase the heap memory for neo4j (I saw a post about this earlier), which removed the OutOfMemoryError, but now I simply get a timeout on the rest execution... -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3498820.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
furthermore, I tried a simple query, that returns about the same number of rows (still around 100K), and increased the timeout of my REST call (to several minutes) - and got my OutOfMemoryError again :) latest query is just g.v(293).in('R_Bought'). Running it through the webadmin console is quick, and my memory usage stays low, etc (all as expected). It's only when going through the REST interface that I start getting memory and/or timeout issues... -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3498879.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Hi Kevin, That is unfortunate. Peter is the man to track down such things in Neo4j REST. Hopefully it's something obvious. Glad the REPL and WebAdmin is speedy. Good luck, Marko. http://markorodriguez.com On Nov 10, 2011, at 10:42 PM, Kevin Versfeld kevin.versf...@gmail.com wrote: furthermore, I tried a simple query, that returns about the same number of rows (still around 100K), and increased the timeout of my REST call (to several minutes) - and got my OutOfMemoryError again :) latest query is just g.v(293).in('R_Bought'). Running it through the webadmin console is quick, and my memory usage stays low, etc (all as expected). It's only when going through the REST interface that I start getting memory and/or timeout issues... -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3498879.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Kevin, So the webadmin console is displaying the 100k nodes ok, men but rest barfs? On Nov 11, 2011 6:42 AM, Kevin Versfeld kevin.versf...@gmail.com wrote: furthermore, I tried a simple query, that returns about the same number of rows (still around 100K), and increased the timeout of my REST call (to several minutes) - and got my OutOfMemoryError again :) latest query is just g.v(293).in('R_Bought'). Running it through the webadmin console is quick, and my memory usage stays low, etc (all as expected). It's only when going through the REST interface that I start getting memory and/or timeout issues... -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3498879.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Kevin, how large is the dataset that is build up? I'm not sure but the REST Plugin and the Webadmin use different implementations where webadmin streams the results with ajax and the REST plugin builds up a full string result. Do you need all of the data? Or would it be possible to page it? Or to add some code to pre-process the data and just return the minimum that is needed. Adding streaming to the cypher + gremlin pluings would be also a nice option, perhaps you'd like to add an github issue for that. Cheers Michael Am 11.11.2011 um 06:42 schrieb Kevin Versfeld: furthermore, I tried a simple query, that returns about the same number of rows (still around 100K), and increased the timeout of my REST call (to several minutes) - and got my OutOfMemoryError again :) latest query is just g.v(293).in('R_Bought'). Running it through the webadmin console is quick, and my memory usage stays low, etc (all as expected). It's only when going through the REST interface that I start getting memory and/or timeout issues... -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3498879.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Perfect, thanks! (Seems so obvious now... *sigh*) At least I now have the easier query done, and can get on to the tricky ones *nervous* -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3489600.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
hi again I suspect I'm missing something small, but when I run the following in the webadmin console, I don't get any output? m = [:]; g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops); true}.cap.next().sort{a, b - a.value = b.value}.keySet [] (m is empty too...) Thanks for the info on cap, by the way: its awesome. :) -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3486381.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
hi again I've played around a bit more, and this is the query that currently works best for me... would anyone mind reviewing it for me please? Feels a little like I'm getting the right answer, but the wrong way gremlin m = [:]; gremlin g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops); true} gremlin m.sort{a - a.value}._() And, that sort tripped me up a few times :) -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3486996.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Hey, I've played around a bit more, and this is the query that currently works best for me... would anyone mind reviewing it for me please? Feels a little like I'm getting the right answer, but the wrong way gremlin m = [:]; gremlin g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops); true} gremlin m.sort{a - a.value}._() And, that sort tripped me up a few times :) Everything looks good except your m.sort{}, which should be something like this: m.sort{a,b - a.value = b.value} The provided closure is a comparator. For a java.util.Map, the comparison is happening between two Map.Entry objects. Thus, your sort needs two inputs (a,b) and then the value of those Entry objects is a.value and b.value, respectively. Hope that is clear. *** Also, note that if you don't want to see output from your g.v(162)... expression, simply do -1 as it will while(expr.hasNext()) and thus, fill the map without burdensome System.out.println()s. *** Enjoy, Marko. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Great! Thanks Marko, this has been very helpful. I did realise my mistake on the sort: when I tried it the way you suggested originally, I also had a few other things wrong, and obviously did not apply a methodical approach to solving it. One last question: I need to just return the nodes, at the end of all of this. I figured I needed to do a projection of sorts, and the only thing I could get working was a transform(), as follows: m.sort{a,b - a.value = b.value}._().transform(){a - a.key} Now, I remember in your first reply, you used things like keyset and as List, but I couldn't get that to work... Any thoughts on this? I imagine it's probably safe to say there's a better method to achieve this :) - A closed mouth gathers no feet... On Mon, Nov 7, 2011 at 11:00 PM, Marko Rodriguez-2 [via Neo4j Community Discussions] ml-node+s438527n3488223...@n3.nabble.com wrote: Hey, I've played around a bit more, and this is the query that currently works best for me... would anyone mind reviewing it for me please? Feels a little like I'm getting the right answer, but the wrong way gremlin m = [:]; gremlin g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops); true} gremlin m.sort{a - a.value}._() And, that sort tripped me up a few times :) Everything looks good except your m.sort{}, which should be something like this: m.sort{a,b - a.value = b.value} The provided closure is a comparator. For a java.util.Map, the comparison is happening between two Map.Entry objects. Thus, your sort needs two inputs (a,b) and then the value of those Entry objects is a.value and b.value, respectively. Hope that is clear. *** Also, note that if you don't want to see output from your g.v(162)... expression, simply do -1 as it will while(expr.hasNext()) and thus, fill the map without burdensome System.out.println()s. *** Enjoy, Marko. ___ Neo4j mailing list [hidden email] http://user/SendEmail.jtp?type=nodenode=3488223i=0 https://lists.neo4j.org/mailman/listinfo/user -- If you reply to this email, your message will be added to the discussion below: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3488223.html To unsubscribe from Gremlin - how to flatten a tree, and sort, click herehttp://neo4j-community-discussions.438527.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=3480586code=a2V2aW4udmVyc2ZlbGRAZ21haWwuY29tfDM0ODA1ODZ8LTE5MTM2MjYxMjE=. -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3489554.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Marko, And I'm saying nasty with a South African accent so you know its dirty. Thanks to working with Romiko, I'm getting an eerily clear mental image of that. -- Tatham ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Hi, I would do it like this: m = [:] g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops); true} -1 m.sort{a, b - a.value = b.value}.keySet as List In short, fill up a Map (m) with key being the vertex and value being the number of hops (or times through the loop). Then sort the map by the number of times through the loop and return the keySet. Since you wanted a List (not a Set), then as List the Set result. HTH, Marko. http://markorodriguez.com On Nov 4, 2011, at 10:25 AM, baldric wrote: I'm very new to much of this, and have a particularly ingrained relational slant to my career, unfortunately. I'm in the process of doing a proof of concept for a product, using neo4j, and gremlin over REST (we're developing in c#) What I'm trying to do at the moment is load a graph (representing a sort of flexible taxonomy), into a flattened list. So, given a starting node, find all associated nodes across a particular relationship type, no matter how far away. I will ultimately need this in a list, and I want the list sorted by how far away each node is (am I correct in referring to this as hops?) Anyway, my best attempt at the unsorted query so far looks something like this: (by the way, the unique part worries me a little) x = []; g.v(162).in('R_PartOf').aggregate(x).loop(2){true} -1; x.unique() (Please try not to laugh too much! :) ) How would I alter this to ensure it is sorted by distance from starting node? Thanks in advance! -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3480586.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Can you do it on one line? ;) Great stuff. Cheers, /peter neubauer GTalk: neubauer.peter Skype peter.neubauer Phone +46 704 106975 LinkedIn http://www.linkedin.com/in/neubauer Twitter http://twitter.com/peterneubauer http://www.neo4j.org - NOSQL for the Enterprise. http://startupbootcamp.org/ - Öresund - Innovation happens HERE. On Fri, Nov 4, 2011 at 11:12 AM, Marko Rodriguez okramma...@gmail.com wrote: Hi, I would do it like this: m = [:] g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops); true} -1 m.sort{a, b - a.value = b.value}.keySet as List In short, fill up a Map (m) with key being the vertex and value being the number of hops (or times through the loop). Then sort the map by the number of times through the loop and return the keySet. Since you wanted a List (not a Set), then as List the Set result. HTH, Marko. http://markorodriguez.com On Nov 4, 2011, at 10:25 AM, baldric wrote: I'm very new to much of this, and have a particularly ingrained relational slant to my career, unfortunately. I'm in the process of doing a proof of concept for a product, using neo4j, and gremlin over REST (we're developing in c#) What I'm trying to do at the moment is load a graph (representing a sort of flexible taxonomy), into a flattened list. So, given a starting node, find all associated nodes across a particular relationship type, no matter how far away. I will ultimately need this in a list, and I want the list sorted by how far away each node is (am I correct in referring to this as hops?) Anyway, my best attempt at the unsorted query so far looks something like this: (by the way, the unique part worries me a little) x = []; g.v(162).in('R_PartOf').aggregate(x).loop(2){true} -1; x.unique() (Please try not to laugh too much! :) ) How would I alter this to ensure it is sorted by distance from starting node? Thanks in advance! -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3480586.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Sure: m = [:]; g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops); true}.cap.next().sort{a, b - a.value = b.value}.keySet [] Marko. http://markorodriguez.com On Nov 4, 2011, at 12:17 PM, Peter Neubauer wrote: Can you do it on one line? ;) Great stuff. Cheers, /peter neubauer GTalk: neubauer.peter Skype peter.neubauer Phone +46 704 106975 LinkedIn http://www.linkedin.com/in/neubauer Twitter http://twitter.com/peterneubauer http://www.neo4j.org - NOSQL for the Enterprise. http://startupbootcamp.org/- Öresund - Innovation happens HERE. On Fri, Nov 4, 2011 at 11:12 AM, Marko Rodriguez okramma...@gmail.com wrote: Hi, I would do it like this: m = [:] g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops); true} -1 m.sort{a, b - a.value = b.value}.keySet as List In short, fill up a Map (m) with key being the vertex and value being the number of hops (or times through the loop). Then sort the map by the number of times through the loop and return the keySet. Since you wanted a List (not a Set), then as List the Set result. HTH, Marko. http://markorodriguez.com On Nov 4, 2011, at 10:25 AM, baldric wrote: I'm very new to much of this, and have a particularly ingrained relational slant to my career, unfortunately. I'm in the process of doing a proof of concept for a product, using neo4j, and gremlin over REST (we're developing in c#) What I'm trying to do at the moment is load a graph (representing a sort of flexible taxonomy), into a flattened list. So, given a starting node, find all associated nodes across a particular relationship type, no matter how far away. I will ultimately need this in a list, and I want the list sorted by how far away each node is (am I correct in referring to this as hops?) Anyway, my best attempt at the unsorted query so far looks something like this: (by the way, the unique part worries me a little) x = []; g.v(162).in('R_PartOf').aggregate(x).loop(2){true} -1; x.unique() (Please try not to laugh too much! :) ) How would I alter this to ensure it is sorted by distance from starting node? Thanks in advance! -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3480586.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Thanks! I will still need to try this out, but the idea (in your first response) kind of feels more or less like what I knew I needed. I have so many questions now based on the responses so far - it feels like I'm just scratching the surface! Firstly, could you explain the differences between map, list, and set? Secondly, when you reduced it to a single line, you implemented cap and next I've seen these mentioned before, but don't really get it... -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3481402.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Gremlin - how to flatten a tree, and sort
Hi, Thanks! I will still need to try this out, but the idea (in your first response) kind of feels more or less like what I knew I needed. I have so many questions now based on the responses so far - it feels like I'm just scratching the surface! Once you get it, you can get nasty with Gremlin. And I'm saying nasty with a South African accent so you know its dirty. Firstly, could you explain the differences between map, list, and set? Map = java.util.Map List = java.util.List Set = java.util.Set Google them. Secondly, when you reduced it to a single line, you implemented cap and next I've seen these mentioned before, but don't really get it... 'cap' is a bit advanced and requires some knowledge of the theory of Gremlin/Pipes. Here is an explanation. Some steps in Gremlin are called sideEffects because they have an internal data structure that they are manipulating. groupCount is one such sideEffect step. Internal to groupCount is a map (m) -- updating that map is the side-effect of groupCount. If you cap a sideEffect pipe you are saying: Don't output what the input is, while(next) the input and when that is drained, output the internal side-effect data structure. http://tinkerpop.com/maven2/com/tinkerpop/pipes/0.8/api/com/tinkerpop/pipes/transform/SideEffectCapPipe.html Thus, with ...step.step.groupCount(m).cap you are yielding the internal map of groupCount (m), not the output from the previous step. It is a useful technique when you want to insert the side-effect of groupCount (its map) into the data stream. Finally, all Gremlin expressions are Iterators, so next() just returns the next thing in the stream which is the map we just got from cap. Generally, if you are new to Gremlin, don't try and do massive one-liners. I was just trying to show off cause Peter egged me on. HTH, Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user