i have a question regarding the following configuration parameter: lagom.persistence.read-side.cassandra.max-result-size. Is this parameter defining the maximun number of rows of a result set or is it used to limit the number of rows per page for a select query with pagination?
I have the following use case, i want to stream rows from a huge table (the table can have millions of rows). I don’t want to get all the rows at once, but i want to have some kind of pagination.
Can i use the parameter lagom.persistence.read-side.cassandra.max-result-size to specify the pagination size of the result set?
That’s used to set the default fetch size for queries in the DataStax Cassandra driver. The driver does its own internal pagination, which is described in detail in the linked page. This parameter sets the size of each page.
You’ll also want to be sure to use one of the CassandraSession.select methods that returns a Source and avoid selectAll, which will try to consume the whole query into a list.
val statement = new SimpleStatement(
"""
SELECT * FROM itemSummaryByCreatorAndStatus
WHERE creatorId = ? AND status = ?
ORDER BY status ASC, itemId DESC
""", creatorId, status.toString)
statement.setFetchSize(2)
val rs = session.select(statement)
rs.map(a => {
ItemSummary(
a.getUUID("itemId"),
a.getString("title"),
a.getString("currencyId"),
a.getInt("reservePrice"),
api.ItemStatus.withName(a.getString("status"))
)
})
This will do a linear search on the results right ? dropping elements before offset.
Cassandra also supports a pageState, any reasons to not use that which I might have missed … (other than cross version constraints)
Was able to get a minimal working paging API with pageState and fetchSize support
Thanks for pointing me to the latest code, even I am doing something similar. Whenever I get the result set, I am sending the pageState (resultset.executionInf()…getPagingState().toString() ) in the response as next, and this is expected in the following API call as param start. This is similar to what you and Tim are suggesting. Thanks!
I was thinking that Lagom itself provides some underlying API to paginate to UI, and I was doing it the wrong way!!! Thanks a lot. Do tell if you think of some more efficient way of handling paging.