How to to get total count for pagination with gremlin query using java Apache thinker pop

I need to implement pagination in my application. I'm unable to get the total count. can someone help me how to get the total count of records.
8 Replies
gdotv
gdotv2y ago
There's a good example of how to do pagination in gremlin in the tinkerpop docs, check https://tinkerpop.apache.org/docs/current/recipes/#pagination It also contains a few more "recipes" for common graph database operations
kelvinl2816
kelvinl28162y ago
Which Graph Database are you using @siva pasupuleti ? When you say unable to get the total count, are you getting an error?
siva pasupuleti
@Kelvin Lawrence I'm using Janus db
spmallette
spmallette2y ago
i'd also offer as reference: https://stackoverflow.com/questions/39826983/how-to-perform-pagination-in-gremlin and the notable blog post from CosmosDB on the matter: https://jayanta-mondal.medium.com/the-curious-case-of-pagination-for-gremlin-queries-d6fd9518620 that said, to follow up on kelvin's question, could you say why you are unable to get the total count? is there an error or are you saying more that you're not sure how to do it? do these resources help?
Stack Overflow
How to perform pagination in Gremlin
In Tinkerpop 3, how to perform pagination? I want to fetch the first 10 elements of a query, then the next 10 without having to load them all in memory. For example, the query below returns 1000,000
Medium
The curious case of Pagination for Gremlin queries
Why TinkerPop graph databases do not support pagination? What can we do as application developers? What else can we achieve as a…
siva pasupuleti
@spmallette Thanks for your reply, currently to retrieve the data from Janus db I'm using the below query, once I got a response from the graph traversal source, I will map this response into the java dto object. List<Map<Object, Object>> node = g.V().has("name", name).has("type", P.within(typeList)).has("system", P.within(systemList )) .local(.properties().group().by(.key()).by(__.value())).skip(0).limit(10).toList(); so, here is how can we get the total count of records for the pagination, tried many ways to get the total count from the graph traversal source but had no luck. Can you please tell me which modification is needed to get a total count of records? thanks.
spmallette
spmallette2y ago
Well, one way to do it is to just copy the example from the link i provided to StackOverflow:
g.V().
has("name", name).
has("type", P.within(typeList)).
has("system", P.within(systemList)).
local(properties().group().by(key()).by(__.value())).
fold().as('page','total').
select('page','total').
by(range(local, 0, 10)).
by(count(local))
g.V().
has("name", name).
has("type", P.within(typeList)).
has("system", P.within(systemList)).
local(properties().group().by(key()).by(__.value())).
fold().as('page','total').
select('page','total').
by(range(local, 0, 10)).
by(count(local))
but if you choose to implement any pagination in any way, it's important to understand what's written in those links about the issues with pagination and Gremlin.
siva pasupuleti
siva pasupuleti17mo ago
thanks for your help @spmallette, I added your code in my IDE but it's showing local cannot be resolved to a variable.
Want results from more Discord servers?
Add your server