0

Using the gremlin console connected remotely to a Neptune DB instance, I'm trying to range from a given index to the last result. It seems like Neptune doesn't accept range(0,-1). It's not throwing an error when I try it, it's just returning an empty list. My thought is to somehow count and store the results, and use the count as the second argument, but I'm not sure how to do that. I know that this particular case is the same as not using a range, but I'm writing code that takes optional input for the start and limit indices, so I need it to be able to handle input of { start: 0 } without a limit.

Sample data:

g.addV().addV().addV()

Traversals and outputs:

g.V()
==>v[0]
==>v[1]
==>v[2]
g.V().range(0,1)
==>v[0]
g.V().range(1,-1)
==>v[1]
==>v[2]
g.V().range(0,-1)
//returns nothing

I would expect the last traversal to give the same output as the first.

Is there a way to do something like g.V().range(0,count())?

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Meagan Sullivan
  • 117
  • 1
  • 10

1 Answers1

0

What you have looks right in range(0,-1) so I suspect a problem with Neptune. Note that it works fine with TinkerGraph:

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().range(0,-1)
==>v[1]
==>v[2]
==>v[3]
==>v[4]
==>v[5]
==>v[6]

I don't think there is a workaround for specifying the upper end of range() in the way you want. Of course, skip(0) is technically analogous to range(0,-1) but that might not help your case.

gremlin> g.V().values('age').order().skip(2)
==>32
==>35
gremlin> g.V().values('age').order().range(2, -1)
==>32
==>35
stephen mallette
  • 45,298
  • 5
  • 67
  • 135