Add methods accepting `PagingState` to `Query`, `CassandraScrollPosition` and `CassandraPageRequest`
I found there's PagingState class in Cassandra Driver 4 but it seems to Spring Data Cassandra not supporting PagingState of Cassandra Driver 4.x.
https://github.com/apache/cassandra-java-driver/blob/4.x/core/src/main/java/com/datastax/oss/driver/api/core/cql/PagingState.java
Do you have any plan for supporting it?
We do support Cassandra's paging state through CassandraPageRequest and CassandraScrollPosition. You can hand in a ByteBuffer for example:
ResultSet rs;
Query q = Query.empty().pagingState(rs.getExecutionInfo().getPagingState());
Query q = Query.empty().pagingState(CassandraScrollPosition.of(rs.getExecutionInfo().getPagingState()));
What are you trying to achieve? Cassandra's Driver 4 supports transparent pagination in case you wanted to consume a large result set via e.g. Stream<T>.
I was making a simple cursor-based pagination function with CassandraPageRequest,
but I have to convert String(encode/decode with base64) -> ByteBuffer or ByteBuffer -> ByteArray -> String because pagingState's type is ByteBuffer.
I think it's more useful to creating CassandraPageRequest with PagingState (from Cassandra Driver or CassandraScrollPosition).
We did't add support accepting PagingState because the driver reports the state ExecutionInfo.getPagingState() as ByteBuffer. PagingState is a public API so we could introduce methods on Query, CassandraPageRequest, and CassandraScrollPosition accepting PagingState in addition to ByteBuffer.
Do you want to submit a pull request? Happy to provide additional guidance if needed.
OK, I will submit pull request soon. Thank you for considering.
@mp911de Hello, I have a concern about method overloading.
I can't define both public ByteBuffer getPagingState() and public PagingState getPagingState() at the same time,
and similarly, defining both
public static CassandraPageRequest of(Pageable current, @Nullable ByteBuffer pagingState) and
public static CassandraPageRequest of(Pageable current, @Nullable PagingState pagingState) causes a compilation error like "Ambiguous method call" when calling CassandraPageRequest.of(current, null).
I think the only resolution is to make different method names. Could you give me advice?
CassandraPageRequest.of(Pageable, …) is rather an internally used method to construct CassandraPageRequest when creating a Slice result. It isn't really intended for the initial request and so this method should not be used widely in existing code.
However, adding an overload creates ambiguity when using null and that can only be resolved by casting to ByteBuffer or PagingState.