CQL Datastax Java Mapping Set/List query operations

37 views Asked by At

Hi I am currently trying to setup my CQL Dao in order to implement some query functions, however I can't find a way to put a Collection of any objects as an argument because I keep getting this error with the codec: Codec not found for requested operation: [TEXT <-> java.util.List<java.lang.String>]

I tried using this but it didn't work:

@Select(customWhereClause = "labels CONTAINS :labels", perPartitionLimit = "1")
fun dependenciesByLabels(@CqlName("labels") labels: Collection<String>): PagingIterable<Dependency>
3

There are 3 answers

0
Paul On

You likely need to define a codec for your collection, there are some examples here: https://docs.datastax.com/en/developer/java-driver/3.5/manual/custom_codecs/#creating-custom-codecs-for-user-defined-types-ud-ts If that doesn't help, please include your collection/type definition.

0
Aaron On
Codec not found for requested operation: [TEXT <-> java.util.List<java.lang.String>]

So this error message means that you're trying to map a column defined as TEXT (UTF string) to a Java List<String>.

It definitely looks like you're using a collection on the app side, so I would check the table definition and make sure that the column is defined as a List<TEXT>.

0
Pseudow On

I guess my acknowledge in Cassandra were not enough. Indeed, it seems that we can the CONTAINS cassandra operator on Collections with multiple values:

This works:

SELECT * FROM your_table WHERE labels CONTAINS 'label';

This doesn't work:

SELECT * FROM your_table WHERE labels CONTAINS { 'label1', 'label2' };