Nihar
Nihar

Reputation: 51

Gremlin: remove repeated parent edges

My Query:

g.V().has("a","123").has("s","1").has("e","p").has("r","e-1").repeat(outE().where(values("startTime").is(gte("2018-12-15"))).where(values("endTime").is(lte("2018-12-16"))).otherV().simplePath()).emit().path().by(valueMap("a","s")).fold()

I am getting result as

A-->B

A-->B-->C

A-->B-->C-->D

How do I remove the first 2 lines from the output?

Desired output: A-->B-->C-->D

Thanks

Upvotes: 0

Views: 334

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

Don't emit the paths in the first place.

edgeTraversal = outE().
           has("startTime", gte("2018-12-15")).
           has("endTime", lte("2018-12-16")).simplePath(); []
g.V().has("a","123").has("s","1").has("e","p").has("r","e-1").
  repeat(edgeTraversal.clone().inV()).
    until(__.not(edgeTraversal)).
  path().
    by(valueMap("a","s")).fold()

Without the child traversal variable:

g.V().has("a","123").has("s","1").has("e","p").has("r","e-1").
  repeat(outE().
           has("startTime", gte("2018-12-15")).
           has("endTime", lte("2018-12-16")).simplePath().inV()).
    until(__.not(outE().
                   has("startTime", gte("2018-12-15")).
                   has("endTime", lte("2018-12-16")).simplePath())).
  path().
    by(valueMap("a","s")).fold()

Upvotes: 1

Related Questions