Forward pagination with MappedAsync

Is there a way to implement the following asynchronously with MappedAsyncPagingIterable interface with CompletionStage<MappedAsyncPagingIterable> mappedAsyncPage?

I want to implement a linkedin feed feature where first request fetches first 5 rows and the following requests will fetch the next 3 rows

@Override
 public List<Tuple2<String,CustomerRequest>> getCustomerRequestData(final String productId, PreparedStatement ps, final String receiptPeriod, String pagingState)
{
 final int PAGE_SIZE = 10;
 session = cassandraSessionFactory.getSession();
 final List<CustomerRequest> customerRequestdata = new ArrayList<CustomerRequest>();
 try
 {
  final BoundStatement boundStatement = ps.bind(productId, receiptPeriod, PAGE_SIZE);
  boundStatement.setPagingState(PagingState.fromString(pagingState));
  final ResultSet resultSet = session.execute(boundStatement);
  final Iterator<Row> iter = resultSet.iterator();
  final PagingState nextPage = resultSet.getExecutionInfo().getPagingState();
  int remaining = resultSet.getAvailableWithoutFetching();
  for (final Row rowdt : resultSet)
  {
  customerRequestdata.add(constructCustomerReq(rowdt));
  if (--remaining == 0)
   {
    break;
   }
  }
 }
 catch (final Exception e)
 {
  e.printStackTrace();
 }
 return new Tuple2<>(nextPage.toString(), customerRe);

So If I understood correctly, you would like to make an implementation of AsyncPagingIterable that will have a variable page size set to 5 at first and then to 3 for subsequent pages. While that may be possible to do and make driver use it, I’m not sure if I would be able to provide such implementation. I believe it would be also too complicated to be worth the effort.

I’d recommend choosing one page size for the needs of your query and handle the portioning of it on application side and not driver side. For example under the hood, the driver in your application may fetch 10 rows each time, but your application’s front-end will control how many it will show - 5 at first then 3 each time you click “More” button or something like that.

1 Like