Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

sreenivasulu_nallapati_171990 avatar image
sreenivasulu_nallapati_171990 asked ·

How do I define a codec for a set of tuples?

I defined a table as below.

CREATE TABLE IF NOT EXISTS user_favourite2 (
  user_email text, 
  favorites frozen<set<tuple<text, text, text, text>>>, 
  PRIMARY KEY (user_email)
)

select query:

select user_email, favorites from user_favourite2 where user_email=?

When trying to get favorites

List<TupleType> favorites = row.getList("favorites", TupleType.class);

Getting below error.

com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [set<frozen<tuple<varchar, varchar, varchar, varchar>>> <-> java.util.List<com.datastax.driver.core.TupleValue>]

How to define custom codec for frozen<set<tuple<text, text, text, text>>>

codec
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

I don't have a full working example for you but @Cedrick Lunven has a sample implementation for a table which has a CQL map collection whose values are a UDT type which you could adapt for your purposes.

The schema looks like this:

CREATE TABLE videos (
    videoid    uuid,
    ...
    formats    map <text,frozen<video_format>>,
    PRIMARY KEY (videoid)
)
CREATE TYPE IF NOT EXISTS video_format (
    width   int,
    height  int
)

The VideoFormatDtoCodec.java class [code] implements the TypeCode interface used in SampleCode3x_CRUD_04_ListSetMapAndUdt.java app [code].

The code is part of the library of code samples at DataStax Examples. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.