Count on non existing edges to other node with specific property

37 views
Skip to first unread message

Hoda Moradi

unread,
Mar 19, 2018, 5:41:14 PM3/19/18
to Gremlin-users
Hi all,

Pardon my novice question here. I am new in gremlin. I am trying to do a simple count on the non existing edges. I can separately count number students in a university and separately count how many students have math class. I am interested to get the negative count which is how many student in each university does not have a math class and order this count. So my query looks like something like this so far.

 g.V().hasLabel("student").has("university_name","MIT").as("u").groupCount("a").by("university_name").group("b").by("university_name").by(bothE("has").otherV().has("name","math").count()).cap("a","b")

my result looks like this

total number of students are 200 and 50 of them has taken math
[a:[MIT:200],b:[MIT:50]]

I want my results to be

MIT=150


which means 150 students did not taken math class yet. Then I want to order this count for every university.

Daniel Kuppitz

unread,
Mar 19, 2018, 11:17:59 PM3/19/18
to gremli...@googlegroups.com
Since MIT is part of your query, you don't really need it in your result. Hence, instead of MIT=150, just 150 should be fine.
Also, it doesn't look like you need both() - replace that with out() or in(), depending on your schema.

g.V().has("student","university_name","MIT").
  not(both("has").has("name","math")).
  count()

And if the math class is a vertex uniquely identified by its name, you should do this:

g.V().has("class","name","math").as("c").
  V().has("student","university_name","MIT").
  not(where(both("has").as("c"))).
  count()

It's cheaper to check adjacent vertices by their id, instead of than scanning their properties.

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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/48093da7-4c99-4230-b700-2d8ce7950f4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hoda Moradi

unread,
Mar 20, 2018, 9:50:31 AM3/20/18
to Gremlin-users
Thanks Daniel for your response.
I actually need the MIT because I want to generalize for every university then order by the count. So my query should return something like

MIT=150
UTD=20
....

So how should I change the query to group by the university_name and give me the number of students who do not have the mat class. Also Math class is a vertex.

Thanks again,

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Daniel Kuppitz

unread,
Mar 20, 2018, 10:52:44 AM3/20/18
to gremli...@googlegroups.com
Then it's:

g.V().hasLabel("student").
  group().
    by("university_name").
    by(__.not(both("has").has("name","math")).count())

Cheers,
Daniel


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/261696e1-2776-41dd-960a-6ada4ca382d3%40googlegroups.com.

Hoda Moradi

unread,
Mar 22, 2018, 10:44:25 AM3/22/18
to Gremlin-users
Thank you so much for your help,

I have a different question as well. I came to know you are one of the committers on the IncrementalBulkloader code. I know it only accepts single value properties, I wanted to ask did it had any edge case or any specific problem that you decided to only accept single values? I need to load lists as property and I wanted to use IncrementalBulkloader. I know I have to implement new BulkloaderVertexProgram. Can you guide me which part of your code should I change and what edge cases I may find?

Daniel Kuppitz

unread,
Mar 22, 2018, 12:24:32 PM3/22/18
to gremli...@googlegroups.com
I believe it was just because it's unclear how to handle duplicate values in incremental loading. The part that overwrites the current value is right here:


I think that's all you need to change to support multi-values.

Cheers,
Daniel


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/8de44455-ac37-4d1c-9064-8b3e0456b595%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages