I am using datastax cassandra 3.1.0. I have created the following table in cassandra and inserted a record.
CREATE TABLE collect_things ( k int PRIMARY KEY, v frozen <tuple <int, text, double>> );
INSERT INTO collect_things (k, v) VALUES(0, (3, 'bar', 2.1));
select * from collect_things ;
k | v
---+-----------------
0 | (3, 'bar', 2.1)
When I am trying to fetch the above row in Java using Cassandra Mapper with the below code:
this.cluster = Cluster.builder().addContactPoint(node).withPort(port).build();
session = cluster.connect();
MappingManager manager = new MappingManager(session);
Mapper<CollectThings> mapper = manager.mapper(CollectThings.class);
Integer k = 0;
mapper.get(k);
I am getting the below exception:
Exception in thread "main" com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [frozen<tuple<int, varchar, double>> <-> com.datastax.driver.core.TupleType]
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:56)
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:25)
at com.datastax.driver.mapping.DriverThrowables.propagateCause(DriverThrowables.java:41)
at com.datastax.driver.mapping.Mapper.get(Mapper.java:432)
I have the following java bean for the above table. CollectThings.java
import com.datastax.driver.core.TupleType;
import com.datastax.driver.mapping.annotations.Frozen;
import com.datastax.driver.mapping.annotations.PartitionKey;
import com.datastax.driver.mapping.annotations.Table;
@Table(keyspace = "user_info", name = "collect_things")
public class CollectThings {
private Integer k;
private TupleType v;
public CollectThings() {
}
@PartitionKey
public Integer getK() {
return k;
}
public void setK(Integer k) {
this.k = k;
}
@Frozen
public TupleType getV() {
return v;
}
public void setV(TupleType v) {
this.v = v;
}
}
Could somebody please tell how to handle tuple types here? Does mapper out of the box not support cql tuple types?
You should be using TupleValue
instead of TupleType
. TupleType
represents the type information for a particular tuple, where TupleValue
represents an actual value. Using your example, I was able to retrieve data by changing all references of TupleType
to TupleValue
.