2
votes

Two queries related to gremlin are as follows:

  1. Want to stop the traversal when a condition is satisfied during repeated condition check.
g.V().has('label_','A')).emit().repeat(inE().outV()).until(has('stop',1)).project('depth','values').by(valueMap('label_','stop'))

I want the query to stop returning further values when the stop is equal to 1 for the node encountered during the repeat statement. But the query doesn't stop and return all the records. Output required:

=>{label_='A',stop=0}
=>{label_='B',stop=0}
=>{label_='C',stop=1}
  1. Query to return traversal values in the following format considering if edge exists between them. Considering the graph as A->E1->B->E2->C. The output must be as follows
=> A,E1,B
=> B,E2,C

A, B, C, E1, E2 represents properties respectively where is the starting node

1
Could you please provide a Graph example? you can create one in gremlify.com or add a gremlin script that generates some data.noam621
g.addV().property('label_','A').property('stop',0).addV().property('label_','B').property('stop',0).addV().property('label_','C').property('stop',1) similar for edges between A to B and B to CPhoenix

1 Answers

1
votes

For the first part, it seems you traversing on the in edges and not on the out is this on purpose? if so replace the out() in the repeat to in

g.V().has(label, 'A').emit().
  repeat(out()).until(has('stop', 1)).
  project('label', 'stop').
    by(label).
    by(values('stop'))

example: https://gremlify.com/ma2xkkszkzr/1

for the second part, I'm still not sure what you meant if you just want to get all edges with their out and in you can use elementMap:

g.E().elementMap()

example: https://gremlify.com/ma2xkkszkzr/4

and if not supported you can maybe do something like this:

g.E().local(union(
      outV(),
      identity(),
      inV()
    ).label().fold())

example: https://gremlify.com/ma2xkkszkzr/2