QuerFinding literals that aren't presently values of a vertex property

Skip to first unread message


Dec 29, 2021, 11:03:32 PM12/29/21
to Gremlin-users
Good evening,

Given a list of a priori known property values (e.g., names), I'm attempting to use gremlin-python to tell me which of said values are not presently the values of a vertex property.

So for instance, I'd have

g.addV().property('name', 'Alice').addV().property('name', 'Bob').iterate()

...which gives me two vertices, as expected.

...and then suppose I want to compute that 'Charlie' is not a known name at present:

g.inject(['Alice', 'Bob', 'Charlie']).unfold().as_('nm').not_(__.V().has('name', P.eq('nm'))).toList()

...unfortunately, this simply returns the injected list with all three names, where I'd expected it to return simply ['Charlie'].  I've tried some variations on this theme, e.g., using a "where" clause and dropping the "P.eq" clause, but it provides much the same results.  Ultimately, I plan to extend the query further after I load the missing name (e.g., 'Charlie') onto my traverser.  

Any help or pointers is very much appreciated, thanks for your time!



Jan 9, 2022, 5:12:44 AMJan 9
to Gremlin-users
Hi Scott,

Here you go:
    g.withSideEffect('x', ['Alice', 'Bob', 'Charlie']) \
        .V().values('name').aggregate('nm').cap('nm') \

Of course, one can only consider this as an exercise because the query would not scale and result in a full table scan. In any practical implementation you would do something like:

    names = {'Alice', 'Bob', 'Charlie'}
    g.withSideEffect('x', names) \
        .V().values('name').where(P.within('x')) \

so that indices can be triggered for fast lookups of vertices.

Best wishes,   Marc
Op donderdag 30 december 2021 om 05:03:32 UTC+1 schreef sco...@gmail.com:


Jan 9, 2022, 2:30:39 PMJan 9
to Gremlin-users
Thanks much!  

I'll start using the withSideEffect for purposes like this.  I'd been invoking P.within(<python-list>) but I see how withSideEffect up-front can probably improve caching.


Reply all
Reply to author
0 new messages