how to groupCount() order by count(*) in java

881 views
Skip to first unread message

Mohsen Raeesi

unread,
Jan 29, 2018, 5:12:37 AM1/29/18
to Gremlin-users
This is an official example of gremlin console (link):
gremlin> g.V().groupCount().by(label).order(local).by(values,decr)
==>[person:4,software:2]

I want to convert it to a java code like this:
g.V().groupCount().by(T.label).order(Scope.local).by(Order.values(), Order.decr).next();



but java does not accept Order.values() in the above command. It throws this exeption:
Type mismatch Can't assign org.apache.tinkerpop.gremlin.process.traversal.Order[] to org.apache.tinkerpop.gremlin.process.traversal.Traversal

Robert Dale

unread,
Jan 29, 2018, 5:32:08 AM1/29/18
to gremli...@googlegroups.com

http://tinkerpop.apache.org/docs/current/reference/#order-step

NOTE
The values and keys enums are from Column which is used to select "columns" from a MapMap.Entry, or Path.




Robert Dale

--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/a4d99001-d535-4eba-8f6f-905fce893d4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mohsen Raeesi

unread,
Jan 29, 2018, 5:56:51 AM1/29/18
to gremli...@googlegroups.com
Thanks Robert
This is solution:
​g.V().groupCount().by(T.label).order(Scope.local).by(Column.values, Order.decr).next();


--
You received this message because you are subscribed to a topic in the Google Groups "Gremlin-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gremlin-users/awclwrrUgv4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CABed_4oPgbDNGx_dk2Rh0_wYYaSz-uq4QYc7tuSwKc9CXx1MbQ%40mail.gmail.com.

Yura A

unread,
Jan 29, 2018, 10:39:39 AM1/29/18
to Gremlin-users
This should work: g.V().groupCount().by(T.label).order(Scope.local).by(Column.values, Order.decr).next();

Mohsen Raeesi

unread,
Jan 30, 2018, 3:24:16 AM1/30/18
to gremli...@googlegroups.com
An Important problem in learning Gremlin using Java

One of my confusing problem is "How to find class of static imports of Gremlin Console in Java?"

for example "values" in this topic is an instance of it.
or in the following example of "Select step" what is the class of first, last and all ?
gremlin> g.V(1).as("a").repeat(out().as("a")).times(2).select(first, "a")
==>v[1]
==>v[1]
gremlin> g.V(1).as("a").repeat(out().as("a")).times(2).select(last, "a")
==>v[5]
==>v[3]
gremlin> g.V(1).as("a").repeat(out().as("a")).times(2).select(all, "a")
==>[v[1],v[4],v[5]]
==>[v[1],v[4],v[3]]

I encounter with these problems many time in learning Tinkerpop using Java.  
Do you have any straight forward solution?

Regards,


On Mon, Jan 29, 2018 at 1:52 PM, Yura A <yura...@gmail.com> wrote:
This should work: g.V().groupCount().by(T.label).order(Scope.local).by(Column.values, Order.decr).next();

--
You received this message because you are subscribed to a topic in the Google Groups "Gremlin-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gremlin-users/awclwrrUgv4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-users+unsubscribe@googlegroups.com.

Stephen Mallette

unread,
Jan 30, 2018, 6:37:02 AM1/30/18
to Gremlin-users
javadoc is useful here:


specifically:


though....perhaps we could add something to the reference docs about the various expressions that are statically imported to make things easier.





--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAMy_dw0%2BGLVwft%2BgsncDBO%2BR2nSOs1kEEg%3D1yQhmpfa%2B5HS3ow%40mail.gmail.com.

Kelvin Lawrence

unread,
Jan 30, 2018, 9:31:56 AM1/30/18
to Gremlin-users
I would agree this is something that people find difficult, making the jump from the Gremlin console to stand alone Java code and figuring out what the Console has done for you that you need to do for yourself in stand alone code. I think there are a few categories (1) Static imports, (2) knowing when to do iterate() etc. (3) Handling exceptions (4) Learning to use things like toList() to both capture a result as well as test for "no result"

FWIW on the book front I have been working on the Java section and am in the middle of significantly expanding the coverage of all these areas.

Cheers,
Kelvin


On Tuesday, January 30, 2018 at 2:24:16 AM UTC-6, Mohsen Raeesi wrote:
An Important problem in learning Gremlin using Java

One of my confusing problem is "How to find class of static imports of Gremlin Console in Java?"

for example "values" in this topic is an instance of it.
or in the following example of "Select step" what is the class of first, last and all ?
gremlin> g.V(1).as("a").repeat(out().as("a")).times(2).select(first, "a")
==>v[1]
==>v[1]
gremlin> g.V(1).as("a").repeat(out().as("a")).times(2).select(last, "a")
==>v[5]
==>v[3]
gremlin> g.V(1).as("a").repeat(out().as("a")).times(2).select(all, "a")
==>[v[1],v[4],v[5]]
==>[v[1],v[4],v[3]]

I encounter with these problems many time in learning Tinkerpop using Java.  
Do you have any straight forward solution?

Regards,

On Mon, Jan 29, 2018 at 1:52 PM, Yura A <yura...@gmail.com> wrote:
This should work: g.V().groupCount().by(T.label).order(Scope.local).by(Column.values, Order.decr).next();

--
You received this message because you are subscribed to a topic in the Google Groups "Gremlin-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gremlin-users/awclwrrUgv4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-user...@googlegroups.com.

Kelvin Lawrence

unread,
Jan 30, 2018, 11:25:18 AM1/30/18
to Gremlin-users
Mohsen, you can see a snapshot of what I have done so far in this area at the link below. This is still work in progress and I am still working on it but I definitely understand the concern and want to help fill the gaps here.

http://kelvinlawrence.net/book/Gremlin-Graph-Guide.pdf

Cheers,
Kelvin

Kelvin Lawrence

unread,
Jan 30, 2018, 2:13:45 PM1/30/18
to Gremlin-users
Hi again Mohsen, I should have added that sections 6.1.5 thru 6.1.7 are the sections I have been working on to try and help Java programmers bridge the gap from the Gremlin console. Please take a look and see if that type of material is useful. Feel free to suggest things I should add there or that should be added to the official Gremlin docs. I like Stephen's idea of adding a section on the key Enums to the TinkerPop docs.

Cheers
Kelvin

Kevin Gallardo

unread,
Jan 31, 2018, 10:41:57 AM1/31/18
to Gremlin-users
Concerning the question

One of my confusing problem is "How to find class of static imports of Gremlin Console in Java?"

Typing :show imports will display the current import of the console, by default currently this is what I get:

gremlin> :show imports
Custom imports:
  org.apache.tinkerpop.gremlin.structure.*
  org.apache.tinkerpop.gremlin.structure.util.*
  org.apache.tinkerpop.gremlin.process.traversal.*
  org.apache.tinkerpop.gremlin.process.traversal.step.*
  org.apache.tinkerpop.gremlin.process.remote.*
  org.apache.tinkerpop.gremlin.structure.util.empty.*
  org.apache.tinkerpop.gremlin.structure.io.*
  org.apache.tinkerpop.gremlin.structure.io.graphml.*
  org.apache.tinkerpop.gremlin.structure.io.graphson.*
  org.apache.tinkerpop.gremlin.structure.io.gryo.*
  org.apache.commons.configuration.*
  org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.*
  org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.*
  org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.*
  org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.*
  org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.*
  org.apache.tinkerpop.gremlin.process.traversal.util.*
  org.apache.tinkerpop.gremlin.process.computer.*
  org.apache.tinkerpop.gremlin.process.computer.bulkdumping.*
  org.apache.tinkerpop.gremlin.process.computer.bulkloading.*
  org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.*
  org.apache.tinkerpop.gremlin.process.computer.traversal.*
  org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.*
  org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.optimization.*
  org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.*
  org.apache.tinkerpop.gremlin.util.*
  org.apache.tinkerpop.gremlin.util.iterator.*
  org.apache.tinkerpop.gremlin.util.function.*
  static org.apache.tinkerpop.gremlin.structure.io.IoCore.*
  static org.apache.tinkerpop.gremlin.process.traversal.P.*
  static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*
  static org.apache.tinkerpop.gremlin.process.computer.Computer.*
  static org.apache.tinkerpop.gremlin.util.TimeUtil.*
  static org.apache.tinkerpop.gremlin.util.function.Lambda.*
  static org.apache.tinkerpop.gremlin.process.traversal.SackFunctions.Barrier.*
  static org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality.*
  static org.apache.tinkerpop.gremlin.structure.Column.*
  static org.apache.tinkerpop.gremlin.structure.Direction.*
  static org.apache.tinkerpop.gremlin.process.traversal.Operator.*
  static org.apache.tinkerpop.gremlin.process.traversal.Order.*
  static org.apache.tinkerpop.gremlin.process.traversal.Pop.*
  static org.apache.tinkerpop.gremlin.process.traversal.Scope.*
  static org.apache.tinkerpop.gremlin.structure.T.*
  static org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent.Pick.*
  org.apache.tinkerpop.gremlin.driver.*
  org.apache.tinkerpop.gremlin.driver.exception.*
  org.apache.tinkerpop.gremlin.driver.message.*
  org.apache.tinkerpop.gremlin.driver.ser.*
  org.apache.tinkerpop.gremlin.driver.remote.*
  groovyx.gbench.*
  groovyx.gprof.*
  static groovyx.gprof.ProfileStaticExtension.*
  org.apache.tinkerpop.gremlin.tinkergraph.structure.*
  org.apache.tinkerpop.gremlin.tinkergraph.process.computer.*

Also, since these are mostly enums, if you have a doubt about one specific import you can still find out where it's coming from with:

gremlin> first.getClass()
==>class org.apache.tinkerpop.gremlin.process.traversal.Pop

Kelvin Lawrence

unread,
Jan 31, 2018, 1:56:26 PM1/31/18
to Gremlin-users
Good point Kevin! I already have coverage of getClass
in the tutorial but I should add a mention of :show imports

Cheers
Kelvin

Mohsen Raeesi

unread,
Feb 2, 2018, 5:54:56 AM2/2/18
to gremli...@googlegroups.com
Hi Kelvin,

Thanks for your comments and your useful free book. I see this book about 2-3 weeks ago. In addition to the official reference, I use the book for learning gremlin. Moreover your sample code on Github helps me a lot.

best wishes,
Mohsen


To unsubscribe from this group and all its topics, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/916ae14b-201a-432c-b011-6a4430405975%40googlegroups.com.

Stephen Mallette

unread,
Feb 2, 2018, 4:10:37 PM2/2/18
to Gremlin-users
It wasn't fun, but I added links for every step to the javadoc along with the various "expression" classes that were relevant to a step (like P or T). I think this is a good example as it includes Cardinality:

http://tinkerpop.apache.org/docs/3.3.2-SNAPSHOT/reference/#addproperty-step

I hope that ends up being helpful a bit to folks who are trying to find full package names to things when they are looking at the step documentation. 

--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAMy_dw1tX5UNYSpXWy-r_idx8JK2QDn21cq_LoNP9m152UVZ8w%40mail.gmail.com.

Mohsen Raeesi

unread,
Feb 4, 2018, 12:29:55 AM2/4/18
to gremli...@googlegroups.com

Stephen Mallette

unread,
Feb 5, 2018, 7:26:04 AM2/5/18
to Gremlin-users
argh....some links work and some don't. asciidoc generation must be mangling the links somehow. looking into it.

Stephen Mallette

unread,
Feb 5, 2018, 7:58:00 AM2/5/18
to Gremlin-users
i figured out the problem. javadoc has special characters in the URLs that asciidoc didn't like...just needed to add some extra syntax to handle that. I didn't republish the documentation so the link are still broken, but on next publish they should be good to go. thanks for pointing out that problem and glad you think that adding these links will be helpful.
Reply all
Reply to author
Forward
0 new messages