1
votes

I am using datastax java driver with mapperd

I want to save epoch as timestamp

device_id | timestamp                       
--------------------------
  2323 | 1595077868994000 
122112 | 2020-07-25 05:30:00.000000+0000

Currently I am using ZonedDate time.. But when I insert record via java code it saves as epoch as shown in Row number 1

insert into table (device_id , timestamp ) VALUES ('122112',toTimestamp(toDate(now()))) ;

However when I insert with query as above it stored timestamp in more readable format How can I configure datastax driver to store timestamp in readable format

Here is my entity

public class Table {

@PartitionKey(value = 0)
private String deviceId;

private Instant timestamp;

Instant was only one which had codec to Timestamp.. I just want to store Timestamp to DB at milli sec accuracy and want it easily readable on UI

THen I am using Object Mapper , Dao and the just calling Save method

@Dao
public interface TableDao {

@Insert
boolean save(Table table);
}
1
Is the timestamp column not of timestamp type? If not, this is a good reason why it should be.Aaron
CREATE TABLE table ( device_id text, timestamp timestampuser1228785
Its timestamp columnuser1228785
Ok. So what does the relevant Java code look like?Aaron
I have update code. I didnt find any codec for java.util.Date which I can use directlyuser1228785

1 Answers

1
votes

Timestamp is stored in Cassandra as 8-byte long number. All conversions to human-readable representations should be done on the client side, for example, converted by DateTimeFormatter. The same happens in cqlsh - it receives 8 byte long number, and convert it into textual representation.

Update, after clarifications: It looks like that code pushes data as microseconds, not as milliseconds, resulting in the values that are muuuuch into the future, and most probably overloading the Python's date/time representation