datastax / cassandra-quarkus

An Apache Cassandra(R) extension for Quarkus
Apache License 2.0
39 stars 28 forks source link

Reactive "if not exists" insertion does not work #183

Closed Fabb111 closed 3 years ago

Fabb111 commented 3 years ago

Hello, I am using the newest cassandra-quarkus-client (1.1.0) in combination with resteasy-reactive and kotlin.

I have the following method in my DAO interface:

@Insert(ifNotExists = true)
fun insertIfNotExists(user: User) : Uni<Void>

which throws

java.lang.IllegalArgumentException: username is not a column in this row
    at com.datastax.oss.driver.internal.core.cql.DefaultRow.firstIndexOf(DefaultRow.java:110)
    at com.datastax.oss.driver.api.core.data.GettableByName.get(GettableByName.java:144)
    at com.datastax.dse.driver.internal.core.cql.reactive.DefaultReactiveRow.get(DefaultReactiveRow.java:260)
...

The User model for reference:

@PartitionKey(0)
val username: String,
@PartitionKey(1)
val phrase: String,
val userId: UUID

The same happens with

@Insert(ifNotExists = true)
fun insertIfNotExists(user: User) : Uni<Boolean>
@Insert(ifNotExists = true)
fun insertIfNotExists(user: User) : MutinyReactiveResultSet
@Insert(ifNotExists = true)
fun insertIfNotExists(user: User) : Uni<User?>

BUT it works when using one of the official Java driver examples (https://docs.datastax.com/en/developer/java-driver/latest/manual/mapper/daos/insert/).

@Insert(ifNotExists = true)
fun insertIfNotExists(user: User) : User?

So not using Mutiny "fixes" the problem. Which would effectively destroy the reactive approach in the whole application.

┆Issue is synchronized with this Jira Task by Unito

adutra commented 3 years ago

Hi, I confirm that I can reproduce the issue. It's related to how MutinyUniResultProducer determines which exact element type the returned Uni should have.

adutra commented 3 years ago

Unfortunately the fix would involve removing the Producer + ServiceLoader mechanism and switch to proper compile-time code generation using the existing cassandra-quarkus-mapper-processor module. I will try to allocate some time for it soon.