spring-data-cassandra icon indicating copy to clipboard operation
spring-data-cassandra copied to clipboard

Add methods accepting `PagingState` to `Query`, `CassandraScrollPosition` and `CassandraPageRequest`

Open oliviarla opened this issue 6 months ago • 4 comments

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?

oliviarla avatar Jun 21 '25 04:06 oliviarla

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>.

mp911de avatar Jun 23 '25 12:06 mp911de

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).

oliviarla avatar Jun 24 '25 04:06 oliviarla

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.

mp911de avatar Jun 24 '25 07:06 mp911de

OK, I will submit pull request soon. Thank you for considering.

oliviarla avatar Jun 24 '25 07:06 oliviarla

@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?

oliviarla avatar Jul 12 '25 12:07 oliviarla

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.

mp911de avatar Jul 14 '25 06:07 mp911de