I'm trying to access C* from my spring code in kotlin. It fails with the Primitive type 'int' used as type parameter
error. I suspect it is due to kotlin's magical unboxing of types that can be primitive in JVM. How to work around it? row.getList("c1", Int::class.java)
is the culprit and I definitely need a boxed type here.
Here's a snippet of my code. And no, I can't use CassandraTemplate, in my scenario the schema is very fluid and can be changed in runtime.
@Componentclass Tst( private val cql: ReactiveCqlTemplate,) { val ks = "test1" val table = "some_table" init { runBlocking { cql.execute("create keyspace if not exists $ks with replication = {'class': 'SimpleStrategy', 'replication_factor': 1};") .awaitSingle() cql.execute("drop table if exists $ks.$table;").awaitSingle() cql.execute("""create table if not exists $ks.$table(id bigint,c1 list<int>,primary key (id));""" ).awaitSingle() val someList = listOf(1, 2, 4, 67, 8, 5, 3, 3, 79, 7453457) cql.execute("insert into $ks.$table (id, c1) values (?,?)", 1L, someList ).awaitSingle() val result = cql.query("select c1 from $ks.$table where id = ${1L}") { row, _ -> val result = row.getList("c1", Int::class.java) result }.next().awaitSingle() println(result) } }}
Full exception stack:
Caused by: java.lang.IllegalArgumentException: Primitive type 'int' used as type parameter at com.datastax.oss.driver.shaded.guava.common.base.Preconditions.checkArgument(Preconditions.java:440) at com.datastax.oss.driver.shaded.guava.common.reflect.Types.disallowPrimitiveType(Types.java:525) at com.datastax.oss.driver.shaded.guava.common.reflect.Types.access$200(Types.java:54) at com.datastax.oss.driver.shaded.guava.common.reflect.Types$ParameterizedTypeImpl.<init>(Types.java:267) at com.datastax.oss.driver.shaded.guava.common.reflect.Types.newParameterizedType(Types.java:102) at com.datastax.oss.driver.shaded.guava.common.reflect.Types.newParameterizedTypeWithOwner(Types.java:91) at com.datastax.oss.driver.shaded.guava.common.reflect.TypeResolver.resolveParameterizedType(TypeResolver.java:265) at com.datastax.oss.driver.shaded.guava.common.reflect.TypeResolver.resolveType(TypeResolver.java:220) at com.datastax.oss.driver.shaded.guava.common.reflect.TypeToken.where(TypeToken.java:231) at com.datastax.oss.driver.api.core.type.reflect.GenericType.listOf(GenericType.java:126) at com.datastax.oss.driver.api.core.data.GettableByIndex.getList(GettableByIndex.java:499) at com.datastax.oss.driver.api.core.data.GettableByName.getList(GettableByName.java:580) at com.example.Tst$1.invokeSuspend$lambda$0(Tst.kt:49) at org.springframework.data.cassandra.core.cql.ReactiveRowMapperResultSetExtractor.lambda$extractData$0(ReactiveRowMapperResultSetExtractor.java:61) at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:179) at reactor.core.publisher.FluxFlattenIterable$FlattenIterableSubscriber.drainAsync(FluxFlattenIterable.java:453) at reactor.core.publisher.FluxFlattenIterable$FlattenIterableSubscriber.drain(FluxFlattenIterable.java:724) at reactor.core.publisher.FluxFlattenIterable$FlattenIterableSubscriber.onNext(FluxFlattenIterable.java:256) at reactor.core.publisher.FluxExpand$ExpandBreathSubscriber.onNext(FluxExpand.java:118) at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2571) at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2367) at reactor.core.publisher.FluxExpand$ExpandBreathSubscriber.onSubscribe(FluxExpand.java:112) at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:55) at reactor.core.publisher.Mono.subscribe(Mono.java:4563) at reactor.core.publisher.FluxExpand$ExpandBreathSubscriber.drainQueue(FluxExpand.java:179) at reactor.core.publisher.MonoExpand.subscribeOrReturn(MonoExpand.java:54) at reactor.core.publisher.Flux.subscribe(Flux.java:8821) at reactor.core.publisher.MonoFlatMapMany$FlatMapManyMain.onNext(MonoFlatMapMany.java:196) at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122) at reactor.core.publisher.MonoCompletionStage$MonoCompletionStageSubscription.apply(MonoCompletionStage.java:121) at reactor.core.publisher.MonoCompletionStage$MonoCompletionStageSubscription.apply(MonoCompletionStage.java:67) at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:934) at java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:911) at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147) at com.datastax.oss.driver.internal.core.cql.CqlRequestHandler.setFinalResult(CqlRequestHandler.java:324) at com.datastax.oss.driver.internal.core.cql.CqlRequestHandler.access$1500(CqlRequestHandler.java:95) at com.datastax.oss.driver.internal.core.cql.CqlRequestHandler$NodeResponseCallback.onResponse(CqlRequestHandler.java:655) at com.datastax.oss.driver.internal.core.channel.InFlightHandler.channelRead(InFlightHandler.java:257) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:840)