Find the target vertex which can be reached from the all outgoing edges after 1 hop

70 views
Skip to first unread message

kishan...@gmail.com

unread,
Sep 6, 2020, 10:00:42 AM9/6/20
to Gremlin-users
I want to find the target vertex which can be reached from all outgoing edges after 1 hop. (so basically skipping the immediate hop (Action))

I have created the following image to explain the scenario better.

criticalaction.png

So here there are Critical Action Vertexes created which are connected with some actions.
There are some other nodes which are connected to different actions.

What am I looking for here?
So here CriticalAction1 has 2 outgoing links that connect to actions and Node1 is connected to 3 actions but 2 of them are the same which are marked as Critical Action. 
So I want to find only those nodes which have all the actions connected with any Critical Action.

The output should be only Node1 and NOT Node2.
Reason: Node2 has only 1 action which is critical. The condition is it should have all the actions which are marked as CriticalAction.

Since I am starting a new journey to Gremlin, I am a little bit confused in this. Your help would be really helpful to me.

Thanks.


Kishan Gajjar

unread,
Sep 6, 2020, 10:00:43 AM9/6/20
to Gremlin-users

I want to find all the Vertexes which are connected to actions(with edge label allow), those are marked as critical by CriticalAction1. 


The condition is that It should be connected with all the actions which are marked as critical action by CriticalAction1 vertex.


So in following image, since CriticalAction1 has 2 actions Action1 & Action2.

Node1 is connected with total 3 actions including Action1 & Action2. So it should be output result.

Node2 is connected with only 1 action. which doesn't satisfy the criteria that it should be connected with all the actions which are marked as critical by CriticalAction1.


criticalaction.png


Amiya

unread,
Sep 6, 2020, 1:04:18 PM9/6/20
to Gremlin-users
Hi,

I tried with below query to find the result. 

g.V().has('criticalAction', 'name', 'Critical Action1').
    out('ca').aggregate('actions').  // Find all the actions
    in('allow').groupCount().by('name').as('x') // Find all the nodes from those actions and group them and count 
    select('actions').count(local).as('action_count').
    select('x').unfold().
          filter(select(values).as('t').where('t', eq('action_count'))). // Check for which node, number of actions of critical action are equal to group count 
    select(keys)

If someone wants to improve the query, you can use sample graph available at https://gremlify.com/t5err29p51/2

Cheers,
Amiya

jimsk...@gmail.com

unread,
Sep 6, 2020, 4:25:55 PM9/6/20
to Gremlin-users
The gremlify thing is cool. I'd not seen it before.

If I've understood correctly, here's another solution:

g.V().hasLabel("node").as("n").
    where(
        V().has('criticalAction', 'name', 'Critical Action1').out("ca").not(in("allow").where(eq("n")))
     )

For each node n, try and find a critical action that is not connected to it.

Jim
Reply all
Reply to author
Forward
0 new messages