filter nodes in where without fold/unfold

119 views
Skip to first unread message

Davide Lo Bartolo

unread,
Jan 28, 2024, 8:40:00 AMJan 28
to Gremlin-users
Hi,
I try to simply my real problem using a graph with only 3 nodes a->b->c.

I expect the node 'b' as result. The only way I found is:

g.V()
  .has(T.id, within('a', 'b'))
  .as('myAlias')
  .fold()
  .as('folded')
  .unfold()
  .out('outlink') //<-- ['b','c']
  .where(within('folded'))

But with a big graph the fold/unfold steps are very slow.
Any advice to avoid fold/unfold and use alias in where to get 'b' node?

Thanks
David

Valentyn Kahamlyk

unread,
Jan 30, 2024, 3:43:49 PMJan 30
to Gremlin-users
Hi David,

if you have 'a' and 'c' then to get 'b'
 g.V('a').out().where(out().hasId('b'))

Yang Xia

unread,
Jan 31, 2024, 3:47:43 PMJan 31
to gremli...@googlegroups.com
Also to just link some resources to help with common usage patterns that may be more extensive, feel free to checkout https://tinkerpop.apache.org/docs/current/recipes/, and more specifically on where() usage https://www.kelvinlawrence.net/book/PracticalGremlin.html#where

--
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/d4cfe20b-1440-4be0-ae5a-1b4b9b22ca0bn%40googlegroups.com.

Davide Lo Bartolo

unread,
Feb 1, 2024, 8:52:09 AMFeb 1
to Gremlin-users
Thanks for the replies.
I think I didn't explain the problem correctly. I don't know the vertex ids neither the ones in the has(T.Id, ..) filter nor the ones in the where clause.
My target is to make an intersection between the .out() nodes and the previous nodes set.

g.V()
  .FILTER_SOMEHOW() //<-- this is the filtered traversal, I have to take it as it is
  .as('myAlias') //<-- this is my boundary
  .out('outlink') // <-- takes all 'out' nodes
  .where(HOW_FILTER_NODES_WITHIN_MY_ALIAS?) <-- I want the 'out' nodes included in 'myAlias', excluding nodes that fall outside myAlias.. should get node 'b' in the previous post

I hope this is a better explanation of my problem.

Davide Lo Bartolo

unread,
Feb 3, 2024, 4:11:22 AMFeb 3
to Gremlin-users
Hi all,
 the solution may be the "as" step in "where" one, stated here by Kelvin Lawrence (e.g. here). 

In that example:
"Starting at JFK, look at all the places we can fly to but only keep those airports that do not have a route back to JFK"

g.V().has('code','JFK').as('s').
      out().as('d').
      where(__.not(out().as('s'))) // "Inside the where step it provides a convenient shorthand way to refer back to the departure airport."

My case should be something like that:

g.V().hasId(within('a','b')).as('myAlias').
    out('outlink').
    where(__.as('myAlias')) // <-- still not working :(
Reply all
Reply to author
Forward
0 new messages