1
votes

My code, which works on the 2.1 version of the driver, is failing on 2.2-rc2.

Here is the stacktrace:

Exception occurred in target VM: Value accountExpiryDate is of type timestamp 
com.datastax.driver.core.exceptions.InvalidTypeException: Value accountExpiryDate is of type timestamp
    at com.datastax.driver.core.AbstractGettableByIndexData.checkType(AbstractGettableByIndexData.java:75)
    at com.datastax.driver.core.AbstractGettableByIndexData.getDate(AbstractGettableByIndexData.java:192)
    at com.datastax.driver.core.AbstractGettableData.getDate(AbstractGettableData.java:26)
    at com.datastax.driver.core.AbstractGettableData.getDate(AbstractGettableData.java:113)
1
Welcome to Stackoverflow. I am sorry, but I am missing the question. - Emz
Can you create a patch that shows the difference? That would help me understand what was changed. - Andy Tolbert
Welcome! People have voted down you question as it doesn't seem to be a question. (It's a big report, right?) Also given that Cassandra is open source under active development it seems odd to post this code over here rather than log a bug over at Apache or seek out the emails lists that the developers use and ask them about it. - simbo1905

1 Answers

6
votes

I'm assuming you must be using 2.2.0-rc2 (given the presence of CodecRegistry) or using the 2.2 branch. This isn't a bug, but I agree that it is pretty misleading. Just to clarify, is there any code in the 2.2 documentation that indicates getDate() should work for timestamp?

In java-driver 2.0 and 2.1 getDate() maps to the CQL timestamp type and returns a Date object:

/**
 * Returns the {@code i}th value as a date.
 *
 * @param i the index ({@code 0 <= i < size()}) to retrieve.
 * @return the value of the {@code i}th element as a data. If the
 * value is NULL, {@code null} is returned.
 *
 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
 * @throws InvalidTypeException if value {@code i} is not of type TIMESTAMP.
 */
public Date getDate(int i);

However, in java-driver 2.2+ it instead maps to the getDate() maps to the date type and returns a LocalDate object:

/**
 * Returns the {@code i}th value as a date (without time).
 *
 * @param i the index ({@code 0 <= i < size()}) to retrieve.
 * @return the value of the {@code i}th element as an date. If the
 * value is NULL, {@code null} is returned.
 *
 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
 * @throws InvalidTypeException if value {@code i} is not of type DATE.
 */
public LocalDate getDate(int i);

This is because in cassandra 2.2 new CQL types were added for time and date. It thus seemed appropriate in the driver to update the method definitions. You can now retrieve timestamp types as java.util.Date objects by using getTimestamp(). This change is documented in the Upgrade Guide for 2.2.0-rc2 under section #14:

Getters and setters have been added to “data-container” classes for new CQL types:

getByte/setByte for the TINYINT type
getShort/setShort for the SMALLINT type
getTime/setTime for the TIME type
getDate/setDate for the DATE type

The methods for the TIMESTAMP CQL type have been renamed to getTimestamp and setTimestamp.

This affects Row, BoundStatement, TupleValue and UDTValue.