Interaction of "not" and "match" steps

220 views
Skip to first unread message

lists+gre...@krejci.pw

unread,
Oct 3, 2016, 10:30:50 AM10/3/16
to gremlin-users
Hi,

In the query below, I'm trying to find all vertices that have "propA" and
"propB" properties set to a different value. The below query complains about
an unsolvable match pattern. Is that a bug or am I doing something wrong in
the query?

graph.addVertex("propertyA", 1, "propertyB", 2);

graph.traversal().V().not(
__.match(
__.as("a").values("propertyA").as("propA"),
__.as("a").values("propertyB").as("propB"))
.where("propA", P.eq("propB"))
.select("a")
);

Because the above is a (simplified) generated query, I'm using a "not" step
instead of simply using P.neq.

Regards,

--
Lukas Krejci

Daniel Kuppitz

unread,
Oct 3, 2016, 10:43:05 AM10/3/16
to gremli...@googlegroups.com
Why so complicated? This should provide the correct result:

g.V().match(
    __.as("a").values("propertyA").as("propA"),
    __.as("a").values("propertyB").as("propB")
  ).where("propA", neq("propB")).select("a")

Another way would be:

g.V().filter(valueMap("propertyA","propertyB").where("propertyA", neq("propertyB")))

Cheers,
Daniel



--
Lukas Krejci

--
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/50896973.2DW1h1rdbW%40localhost.localdomain.
For more options, visit https://groups.google.com/d/optout.

lists+gre...@krejci.pw

unread,
Oct 3, 2016, 10:56:32 AM10/3/16
to gremli...@googlegroups.com
As I said, we generate the query based on inputs. The "match" part needs to
sometimes be negated, sometimes not. So my initial approach to this was to
simply leave the query "snippet" as is and just negate it when needed. That's
when I discovered this problem.

While in this simplified example P.eq -> P.neq is indeed the simplest
solution, bringing it back to our codebase would be more difficult, because
the "real" query is more complex. I simplified the query to illustrate the
strange behavior...
email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/
gremlin-users/50896973.2DW1h1rdbW%40localhost.localdomain.
For more options, visit https://groups.google.com/d/optout.



--
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/CA%2Bf9seWqOM%3DXCT0nXuZ%3DfTu3neW_3uiZCsEAQmeHLBqfsB4baw
%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.




--
Lukas Krejci

Daniel Kuppitz

unread,
Oct 3, 2016, 12:33:47 PM10/3/16
to gremli...@googlegroups.com
Looks like you've found a bug in NotStep. Here are 2 ugly workarounds:

1. Enable path computations:

g.withPath().V().not(match(...))

2. Add requirements in the parent traversal:

g.V().as("a").not(match(...)).select("a")

Cheers,
Daniel


To view this discussion on the web visit https://groups.google.com/d/msgid/
gremlin-users/50896973.2DW1h1rdbW%40localhost.localdomain
.
For more options, visit https://groups.google.com/d/optout.



--
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

To view this discussion on the web visit https://groups.google.com/d/msgid/
gremlin-users/CA%2Bf9seWqOM%3DXCT0nXuZ%3DfTu3neW_3uiZCsEAQmeHLBqfsB4baw
%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.




--
Lukas Krejci

--
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/3581542.WupXtlzBPQ%40localhost.localdomain.

Robert Dale

unread,
Oct 3, 2016, 12:45:25 PM10/3/16
to gremli...@googlegroups.com
I was thinking that the original query had a misplaced not. It
doesn't make sense to me to not() a select(). What would be the
expected outcome? That is, what is the opposite of a vertex?

I agree what you found is bug. not(match()) should work.

These should also be valid not() queries:

1. not(where()):
g.V().match(__.as("a").values("propertyA").as("propA"),__.as("a").values("propertyB").as("propB")).not(where("propA",
P.eq("propB"))).select("a")

2. where(not()):
g.V().match(__.as("a").values("propertyA").as("propA"),__.as("a").values("propertyB").as("propB")).where("propA",
not(P.eq("propB"))).select("a")
>> email to gremlin-user...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/
>> gremlin-users/50896973.2DW1h1rdbW%40localhost.localdomain.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> 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/CA%2Bf9seWqOM%3DXCT0nXuZ%3DfTu3neW_3uiZCsEAQmeHLBqfsB4baw
>> %40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>> Lukas Krejci
>>
>> --
>> 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.
> --
> 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/CA%2Bf9seXz8yNOGJpPaPvLW3WDNKCAQxfxsPVhJUzo%2B_uwpPKG7A%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--
Robert Dale

Marko Rodriguez

unread,
Oct 3, 2016, 12:56:26 PM10/3/16
to gremli...@googlegroups.com, d...@tinkerpop.apache.org
Hello,

Note that I just pushed a fix to tp31/ and up-merged to master/. Thus, your traversal will work as expected in 3.1.5 and 3.2.3.


gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().not(match(
......1>     __.as("a").values("age").as("b"),
......2>     __.as("a").values("name").as("c")).
......3>       where("b", eq("c")).
......4>     select("a")).
......5>   values("name")
==>marko
==>vadas
==>lop
==>josh
==>ripple
==>peter
gremlin>

Thanks for the find,
Marko.
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/CA%2Bf9seXz8yNOGJpPaPvLW3WDNKCAQxfxsPVhJUzo%2B_uwpPKG7A%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages