1

I am trying to use a filter step to filter vertices by id, but unsure of how to do this.

Here is roughly what I am trying to do.

g.V().has(label, 'Users').filter(id().is(eq("Users:77287168:1051")))
g.V().has(label, 'Users').filter(id().is("Users:77287168:1051"))

Both of the above always return 0 records. However

g.V().has(label, 'Users').filter(hasId("Users:77287168:1051"))

This works as intended and I am getting the a User with the given id.

Again the above is only representational and I would just like to know how/what would it take to do an id() comparison inside my filter function. For instance I am expecting my traversal argument to filter to traverse vertices and I would like to compare it against the current traversal's vertex id.

Sathyakumar Seshachalam
  • 2,013
  • 3
  • 20
  • 32
  • it's possible that `is()` might not be optimizing properly in the traversal. what version of DSE are you using? – stephen mallette Nov 01 '17 at 12:02
  • @stephenmallette The version is DSE 5.1.3. I didn't quite understand is() not being optimized. – Sathyakumar Seshachalam Nov 01 '17 at 13:10
  • @stephenmallette : Some more observation on the `is`. `g.V().has(label, 'Users').filter(label().is('Users')` works. But `userId = g.V("Users:77287168:1051").id(); g.V().has(label, 'Users').filter(label().is(userId))` didn't work and returned 0 results. – Sathyakumar Seshachalam Nov 01 '17 at 13:28
  • i just meant it is likely a bug in DSE Graph. DSE Graph is not recognizing the use of `is()` in that context to use the specified id as a vertex lookup. – stephen mallette Nov 01 '17 at 14:49
  • @stephenmallette: Hi, Are there any workarounds ? In the filter step, If I want to do use id() what are the options available ? – Sathyakumar Seshachalam Nov 02 '17 at 04:35
  • There could be, but you'd need to adjust your question to explain more of what you are doing. Given your example, `hasId()` seems to be the best workaround. – stephen mallette Nov 02 '17 at 09:54
  • I have a code to search for vertices say `Users` and then would like to filter them further based on current user's access privileges. `g.V().has(label, 'Users').filter(V('currentUserId).out('user_groups').hasId(id()))`. `user_group` in that query is only representational, in my eventual workflow, it will be a longer traversal – Sathyakumar Seshachalam Nov 03 '17 at 14:21
  • Based on what you've said there, I don't think you really have a need for use of `hasId()` in the way you are using it. Seems like your the traversal in your comment above simplifies to just: `g.V('currentUserId').out('user_groups').hasId('someGroupId')` I know you say your actual traversal will be much more complex but if you can't provide some minimal example of what you are trying to do that doesn't easily simplify to a different traversal that won't have the problem you're facing, I don't think I can be of much help. fwiw, DSE Graph engineers are looking at the actual problems with `is()` – stephen mallette Nov 08 '17 at 11:45

0 Answers0