1

I trying to mirror the following gremlin code in Python to do pagination.

gremlin> t = g.V().hasLabel('person');[]
gremlin> t.next(2)
==>v[1]
==>v[2]
gremlin> t.next(2)
==>v[4]
==>v[6]

Here are the Python code

    from neptune_python_utils.gremlin_utils import GremlinUtils
    from neptune_python_utils.endpoints import Endpoints

    GremlinUtils.init_statics(globals())

    endpoints = '...'
    gremlin_utils = GremlinUtils(endpoints)

    conn = gremlin_utils.remote_connection()
    g = gremlin_utils.traversal_source(connection=conn)

    t = g.V().hasLabel('my-label')

    cnt, ipp = True, 100
    while cnt:
        r = t.next(ipp)
        if not r: 
            cnt = False

But I'm getting error

  "errorMessage": "'list' object has no attribute 'next'",
  "errorType": "AttributeError"
  on line ---> r = t.next(ipp)

The trace show that the first iteration for r = t.next(ipp) actually ran, but it returned a list object, so there is no .next() anymore. How can I keep the traversal in the iterations?

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
user1187968
  • 7,154
  • 16
  • 81
  • 152
  • Something to be aware of is that this will not give you true server-side pagination. The server will start streaming results back to the client as soon as they are available and all of those results need to be "drained" client-side before the query timeout expires. The results will all be sent to the client regardless of the value used with `next` as quickly as possible. If you want to take this type of approach, performing a `toList` to get all the results and then iterating over that list is the approach to take in many cases. – Kelvin Lawrence Aug 21 '21 at 00:45
  • 1
    As to the exact issue, that is a bit odd as it should work. In some simple tests I was able to make multiple calls to `next` using the same `t`. Which version of the Gremlin Python client are you using? – Kelvin Lawrence Aug 21 '21 at 00:46
  • Were you able to get your code working? I was never able to reproduce what you were seeing. – Kelvin Lawrence Sep 07 '21 at 17:28

0 Answers0