Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first cut: Cassandra flows with support for conditional writes #3165

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

leviramsey
Copy link
Contributor

"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

@leviramsey leviramsey marked this pull request as draft April 5, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant