alpakka
alpakka copied to clipboard
first cut: Cassandra flows with support for conditional writes
"Conditional" write flows result in Either[T, AsyncResultSet]
: the Left[T]
case is for when the write was applied, the Right[AsyncResultSet]
case is when the write wasn't applied (e.g. in an INSERT ... IF NOT EXISTS
there was already a row). Per the Cassandra docs around wasApplied
, if the query is an unconditional write, this will always be a Left
(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 the Either
, but my sense is that this doesn't perfectly map onto the usual right-biasing conventions (the more interesting result is the AsyncResultSet
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:
if (element.wasApplied()) {
// do stuff with element.getContents()
} else {
// do stuff with element.getResultSet()
}
Perhaps the fold
could be incorporated into the stage by requiring an AsyncResultSet => T
, but that actually seems like a fairly niche use case