apple / swift-cassandra-client

Cassandra client in Swift
https://swiftpackageindex.com/apple/swift-cassandra-client/main/documentation/cassandraclient
Apache License 2.0
89 stars 16 forks source link

Expose the paging token API from the C/C++ driver #22

Closed erichmenge closed 1 year ago

erichmenge commented 1 year ago

Adds support for getting/setting a paging token that can be reused.

Motivation:

Cassandra allows for paginated result querying to support iterating over large request sets. This pagination mechanism is currently an implementation detail internal to the client. For end clients talking to a web service, being able to jump to a particular page is useful for larger result sets, especially with unreliable network conditions, or additional business logic and processing that may happen on the end client.

Modifications:

Note that the current implementation mostly just exposes the C/C++ token, which is unsafe to use from untrusted sources without additional care to verify that the token is used for the exact same query. For this reason, I'm exposing this as an OpaquePagingStateToken to use internally. The internal token is itself available via withUnsafeBytes. This is so that people can implement their own safety mechanism on top of this primitive. The withUnsafeBytes should act as a signal that care must be taken, and documentation read.

In the future, we may want to provide a higher order abstraction like the Java client has, where the paging token is made safe by way of hash verification.

This pull request provides some early value for those that need paging tokens, while allowing for additional enhancement in the future, if desired.

Result:

swift-server-bot commented 1 year ago

Can one of the admins verify this patch?

swift-server-bot commented 1 year ago

Can one of the admins verify this patch?

swift-server-bot commented 1 year ago

Can one of the admins verify this patch?

swift-server-bot commented 1 year ago

Can one of the admins verify this patch?

swift-server-bot commented 1 year ago

Can one of the admins verify this patch?

swift-server-bot commented 1 year ago

Can one of the admins verify this patch?

yim-lee commented 1 year ago

@swift-server-bot add to allowlist

erichmenge commented 1 year ago

Updated the PR based on some discussions, also updated the description accordingly.

erichmenge commented 1 year ago

once CI is green!

Looks like I need to go back a few Swift versions...

yim-lee commented 1 year ago

Seems like withMemoryRebound was added in Swift 5.7. Perhaps we add a #if swift(>=5.7) check around the feature?

erichmenge commented 1 year ago

Seems like withMemoryRebound was added in Swift 5.7. Perhaps we add a #if swift(>=5.7) check around the feature?

It took a bit of work to get a Swift 5.4 installation working but looks like everything is good now.