first cut: Cassandra flows with support for conditional writes #3165
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
"Conditional" write flows result in
Either[T, AsyncResultSet]
: theLeft[T]
case is for when the write was applied, theRight[AsyncResultSet]
case is when the write wasn't applied (e.g. in anINSERT ... IF NOT EXISTS
there was already a row). Per the Cassandra docs aroundwasApplied
, if the query is an unconditional write, this will always be aLeft
(for those, the conditional version of the flow is effectively just a less efficient version (extra wrapping/unwrapping) of the existing flow). I'm open to flipping theEither
, but my sense is that this doesn't perfectly map onto the usual right-biasing conventions (the more interesting result is theAsyncResultSet
IMO, even though that could be thought of as the failure).The Java API is a work in progress: this feels like how a sum type would be encoded in a lightweight way in Java and I don't know if it makes sense to expose functional combinators: since the typical next stage in the Scala API would be a
fold
, I think Java code like:Perhaps the
fold
could be incorporated into the stage by requiring anAsyncResultSet => T
, but that actually seems like a fairly niche use case