Warm tip: This article is reproduced from stackoverflow.com, please click
amazon-neptune gremlin

Want two Vertices off the same Edge in Gremlin

发布于 2020-04-23 17:11:37

I have a graph like this

V('Producer')-E('RESPONSIBLE_PRODUCER)->V('Event')<-E('INSPECTED')-V('Engineer')
V('Event')<-E('ALIGNED_PRODUCER')-V('Producer')

That is, each 'Event' vertex has two incoming edges: one that terminates at an 'Engineer' vertex and another that terminates at a 'Producer' vertex. But the function of the Producer vertices are different depend on the edge label.

I want to get the originating Producer, the Event, Engineer and terminating Producer.

I have this gremlin code:

g.V().hasLabel('Producer').
as('responsible').
has('ProdId', 1234567).
out("RESPONSIBLE_PRODUCER").hasLabel('Event').as('event').
in("INSPECTED").hasLabel('Engineer').as('engineer').
select('responsible', 'event', 'engineer').
by(valueMap('name')).by(valueMap('name')).by(valueMap('name'))

That is, I chose a given Producer and get the Event and Engineer then return some details about each of those vertices.

I also want the Producer aligned to the Event in the same query but am not sure how to do this.

Any help is greatly appreciated.

Questioner
fiacre
Viewed
35
gremlify 2020-02-22 19:20

You are looking for project:

g.V().has('Producer', 'ProdId', '1').as('r').
out("RESPONSIBLE_PRODUCER").hasLabel('Event').
project('responsible', 'event', 'engineer', 'aligned').
by(select('r').values('name')).
by(values('name')).
by(in('INSPECTED').values('name')).
by(in('ALIGNED_PRODUCER').values('name'))

You can see a "live" example of your problem here