within() vs where(within())

55 views
Skip to first unread message

HadoopMarc

unread,
Jun 22, 2018, 8:28:46 AM6/22/18
to Gremlin-users
Hi all,

On the TinkerPop modern graph:

gremlin> g.withSideEffect('a',['marko']).V().has('name',within('a'))
gremlin
> g.withSideEffect('a',['marko']).V().has('name',where(within('a')))
==>v[1]
gremlin
> g.V().has('name',within(['marko']))
==>v[1]


Does this make sense, in other words is there any reaon why within would not resolve the 'a' sideEffect when used outside the where() step?

I thought maybe within() without where() would use characters in a string as a range, but also that is not the case. Current behavior is confusing.

Cheers,    Marc

Robert Dale

unread,
Jun 22, 2018, 8:32:53 AM6/22/18
to gremli...@googlegroups.com
It's a nuance of 'where()'.  http://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates

>    Finally, note that where()-step takes a P<String>. The provided string value refers to a variable binding, not to the explicit string value.

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-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/a96f2728-2200-46c1-82fd-72f217c66ff8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

HadoopMarc

unread,
Jun 22, 2018, 9:28:39 AM6/22/18
to Gremlin-users
Thanks for the note!

Indeed, I checked that my query could be written alternatively as:

g.withSideEffect('a',['marko']).V().values('name').as('b').where('b', within('a'))

This is rather verbose, but does not need the awkward has(..., where(within(...)))

Cheers,    Marc

Op vrijdag 22 juni 2018 14:32:53 UTC+2 schreef Robert Dale:

Daniel Kuppitz

unread,
Jun 22, 2018, 11:23:16 AM6/22/18
to gremli...@googlegroups.com
Hi Marc,

I think that's the actual query you're looking for:

gremlin> g.withSideEffect('a',['marko']).V().where(within('a')).by('name').by()
==>v[1]

The first by() refers to the current element, the second by() to the side-effect named 'a'.

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/1f1e51a7-645e-4401-907f-45be7f3f0a9b%40googlegroups.com.

HadoopMarc

unread,
Jun 23, 2018, 5:28:55 AM6/23/18
to Gremlin-users
Hi Daniel,

Thanks, yes, I certainly like your version better because it returns the vertex rather than the property value.

Marc

Op vrijdag 22 juni 2018 17:23:16 UTC+2 schreef Daniel Kuppitz:

HadoopMarc

unread,
Aug 17, 2018, 5:29:36 AM8/17/18
to Gremlin-users
Hi all,

I tried the where().by().by() syntax provided above with multiproperties but got stuck again. Fortunately, my original awkard has(..., where(within())) syntax still works:


gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin
> g.V(1).property(VertexProperty.Cardinality.set,'name','rod')
==>v[1]
gremlin
> g.V(1). valueMap()
==>[name:[marko,rod],age:[29]]

gremlin
> g.withSideEffect('a',['ben','marko']).V().has('name', where(within('a')))
==>v[1]
gremlin
> g.withSideEffect('a',['ben','rod']).V().has('name', where(within('a')))
==>v[1]

gremlin
> g.withSideEffect('a',['ben','marko']).V().where(within('a')).by(values('name')).by()
==>v[1]
gremlin
> g.withSideEffect('a',['ben','rod']).V().where(within('a')).by(values('name')).by()
gremlin> g.withSideEffect('a',['ben','rod']).V().where(within('a')).by(values('name').tail()).by()
==>v[1]




The line with the tail() step only shows what is going on and does not provide a solution. What is the proper way to unfold the name values for the where() syntax [what the has() step apparently does automatically]?

Thanks,     Marc



Op zaterdag 23 juni 2018 11:28:55 UTC+2 schreef HadoopMarc:

Daniel Kuppitz

unread,
Aug 17, 2018, 10:18:14 AM8/17/18
to gremli...@googlegroups.com
I think you want something like this:

g.withSideEffect('a',['ben','rod']).V().filter(values('name').where(within('a')))

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/6af374eb-d9f1-4e6b-b5af-b2c55e9ec0b4%40googlegroups.com.

HadoopMarc

unread,
Aug 18, 2018, 2:41:54 PM8/18/18
to Gremlin-users
Thanks for addressing this question and assuring me that I do not overlook simpeler ways of writing this!

Your suggestion is close to my original query:

g.withSideEffect('a',['ben','rod']).V().has('name'), where(within('a')))
==>v[1]

For completeness (but not addressing the original question), a colleague of mine remarked that if you want readability, forget about the oneliner:

a = Arrays.asList('ben', 'rod')
g
.V().has('name', within(a))
==>v[1]

Thanks again,

Marc


Op vrijdag 17 augustus 2018 16:18:14 UTC+2 schreef Daniel Kuppitz:
Reply all
Reply to author
Forward
0 new messages