[Gremlin] has and hasNot , out and outNot

802 views
Skip to first unread message

Etienne Couritas

unread,
Sep 10, 2014, 9:03:11 AM9/10/14
to gremli...@googlegroups.com
Hello,

I have a gremlin question.

for the graph

[class:'people', name:'robert'] --house-->[color:'blue']
[class:'people', name:'antonio']--house->[color:'yellow']
[class:'people', name:'michel']   //michel is home less

when i want to have all people with a  blue house I do
g.V.has('class','people').as('p').out('house').has('color','blue').back('p')
whit will give me [class:'people', name:'robert']


know I try to filter all people witch have not a blue house 
like it  g.V.has('class','people').as('p').out('house').hasNot('color','blue').back('p')
I would have  [class:'people', name:'antonio'] & [class:'people', name:'michel'] 
but in fact I have just [class:'people', name:'antonio']

I think it's because michel as no adjacency 'house'
So the request I just write is "all people with a none blue house" and not "all people witch have not a blue home"

How can I write such request,( I alway start with  .has('class','people'))

Daniel Kuppitz

unread,
Sep 10, 2014, 9:08:04 AM9/10/14
to gremli...@googlegroups.com
Hi Etienne,

simply do the traversal within a filter step:

g.V.has('class','people').filter({ !it.out('house').has('color','blue').hasNext() })

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/1aa9431a-8d4c-4296-8930-528504b22f3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Etienne Couritas

unread,
Sep 10, 2014, 9:21:12 AM9/10/14
to gremli...@googlegroups.com
My co worker just said to me all my witch should be write which ^^

So 
[class:'people', name:'robert'] --house-->[color:'blue'] -- garden --> [style:'english garden']
[class:'people', name:'antonio']--house->[color:'yellow']
[class:'people', name:'michel'] 

all people with blue house and english garden 

g.V.has('class','people').filter({ it.out('house').has('color','blue').hasNext() }).filter({ it.out('house').out('garden').has('style','english garden').hasNext() })

all people with yellow house and not english garden 

g.V.has('class','people').filter({ it.out('house').has('color','blue').hasNext() }).filter({ !it.out('house').out('garden').has('style','english garden').hasNext() })

I think it's uglyest than with the simple out and has but I will work i thinks.
Thank you Daniel, know I need to find how write it with scala gremlin but it's another question ^^

Daniel Kuppitz

unread,
Sep 10, 2014, 9:37:26 AM9/10/14
to gremli...@googlegroups.com
Don't use .filter() if it's not needed (it's slower than .has()).

g.V.has('class','people').filter({ it.out('house').has('color','blue').hasNext() }).filter({ it.out('house').out('garden').has('style','english garden').hasNext() })

can be:

g.V.has('class','people').as('p').out('house').has('color','blue').out('garden').has('style','english garden').back('p')

and

g.V.has('class','people').filter({ it.out('house').has('color','blue').hasNext() }).filter({ !it.out('house').out('garden').has('style','english garden').hasNext() })

can be:

g.V.has('class','people').as('p').out('house').has('color','blue').filter({ !it.out('garden').has('style','english garden').hasNext() }).back('p')

Cheers,
Daniel


Etienne Couritas

unread,
Sep 10, 2014, 10:06:34 AM9/10/14
to gremli...@googlegroups.com
Why it's slower and how much ?

I use un language for my query witch a convert to gremlin and I prefer generalise my code ( so write the same for the has and hasNot )

it's can be read like people.filter(house.garden.style,english garden) => which is convert to g.V.has('class','people').as('p').out('house').has('color','blue').out('garden').has('style','english garden').back('p')
so when I want to do people.exclude(house.garden.style,english garden) I would like to just have to replace the has by hasNot , in the fact I replace the has(...,Equals,...) by has(...,NotEquals,...)

But if the performances are better by using two different gremlin writing I think I should write to writing because we need performances.

ps: sorry for my english

Daniel Kuppitz

unread,
Sep 10, 2014, 10:30:26 AM9/10/14
to gremli...@googlegroups.com
You can easily test performance differences in the Gremlin shell.


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.

Etienne Couritas

unread,
Sep 10, 2014, 10:48:05 AM9/10/14
to gremli...@googlegroups.com
Twice slower :o

Indeed you convince me !



Cordialement,

Etienne Couritas
tel 06 33 82 47 62
mail e.cou...@gmail.com
addr 26 rue de visien 92400 Courbevoie

SVP, envoyez-moi un accusé de réception. Merci.
Please, send me acknowledgment of receipt. Thanks.


--
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/NFHzgl2BAFY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAO7ueZKPp5Anf7dxpDtRtQ4bJP7GYcGrsg_e7J1iasgdaUm2ng%40mail.gmail.com.

Marko Rodriguez

unread,
Sep 10, 2014, 10:59:28 AM9/10/14
to gremli...@googlegroups.com
Hi,

You might appreciate reading this page:

In Gremlin3, we have made all these "syntactic sugars" hidden from the user unless they explicitly turn on the "Sugar Plugin."

HTH,
Marko.

Etienne Couritas

unread,
Sep 10, 2014, 11:19:43 AM9/10/14
to gremli...@googlegroups.com
Thank you but In my reality I use scala gremlin which use ( I think ) directly pipe.
But I think the new scala gremlin ( with tp3 ) could have a writing near the writing of groovy gremlin so benefice of the same tips than grooby gremlins 
Reply all
Reply to author
Forward
0 new messages