Reputation: 1
I have a small table definition for Cassandra 3 as shown below.
create table if not exists mytable(id uuid primary key, data text, timestamp lastupdated);
I want to be able to map the timestamp column called 'lastupdated' to the java.time.Instant type. This can be handled according to the Cassandra documentation by registering a new Instant codec as documented here https://datastax.github.io/java-driver/manual/custom_codecs/extras/
Following the instructions, including importing com.datastax.cassandra:cassandra-driver-extras:3.1.0 I use the following code to add the Instant codec.
// Extra setup to allow Cassandra Timestamp to map to Java 8 Instant
CodecRegistry myCodecRegistry;
myCodecRegistry = CodecRegistry.DEFAULT_INSTANCE;
myCodecRegistry.register(InstantCodec.instance);
Cluster cluster = Cluster.builder().
addContactPoints(extractAddresses(config())).
withCodecRegistry(myCodecRegistry).build();
When I debug this code I can see that my Cluster object contains the new Instant codec in the cluster.getConfiguration().codecRegistry once it has been initialized.
However, when I execute the cql that creates my table, as defined at the top, I get the following exception, via session.execute :
unknown type xxx.lastupdated :
com.datastax.driver.core.exceptions.InvalidQueryException: Unknown type xxx.lastupdated
I feel that I have missed something obvious as timestamp should be recognized even without the Instant codec, any help would be much appreciated.
Upvotes: 0
Views: 510
Reputation: 5180
Answer is as simple as inverting the column name with the type!
create table if not exists mytable (
id uuid primary key,
data text,
lastupdated timestamp
);
Upvotes: 1