How to implement pagination recipe using Golang SDK

119 views
Skip to first unread message

Laura Poss

unread,
Jul 5, 2023, 6:25:07 PM7/5/23
to Gremlin-users
Hi all,

I'm trying to implement the pagination recipe using the Golang SDK but am stuck on how to correctly translate the example to Go code.

The code I'm currently working with is as follows:

var __ = gremlingo.T__

g.V().HasLabel("tag").
  Fold().
  As("tags", "count").
  Select("tags", "count").
  By(__.Range(__.Local(), 0, 2).
  By(__.Count(__.Local())).
  ToList()

However, when I run this, I keep getting the following error:
java.lang.IllegalStateException: Could not locate exact method given the supplied arguments: DefaultGraphTraversal.local()

I'm very new to Gremlin and don't have a particularly solid grasp on concepts like anonymous traversals so I'm not sure that I've referenced all of the methods correctly. Any pointers would be greatly appreciated! Thanks!

Cole Greer

unread,
Jul 5, 2023, 6:39:47 PM7/5/23
to gremli...@googlegroups.com

Hi Laura,

 

There is perhaps some room for improvement when it comes to GLV translations of many of our examples. I believe the correct translation in this case would be this:

results, err := g.V().HasLabel("tag").

     Fold().

     As("tags", "count").

     Select("tags", "count").

     By(__.Range(gremlingo.Scope.Local, 0, 2)).

     By(__.Count(gremlingo.Scope.Local)).

     ToList()

 

I hope this helps.

 

Regards,

 

Cole Greer


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/f189434b-b458-401d-bc2e-a8d74fd97828n%40googlegroups.com.

Yang Xia

unread,
Jul 5, 2023, 6:46:00 PM7/5/23
to gremli...@googlegroups.com
Also just to add, the confusion might have come from the concept of the local Scope (https://tinkerpop.apache.org/docs/current/reference/#a-note-on-scopes) vs the local Step (https://tinkerpop.apache.org/docs/current/reference/#local-step), which have different usage purposes. 

So the "local" in the recipe example is referring to the local Scope, which is why you are getting the illegal state error: both range() and count() are expecting the Scope local instead of the local step. 

Laura Poss

unread,
Jul 6, 2023, 1:05:07 PM7/6/23
to Gremlin-users
These solutions worked! Thank you so much for the guidance, it's greatly appreciated!
Reply all
Reply to author
Forward
0 new messages