cjds
cjds

Reputation: 8426

Expected a long or a date string representation of a timestamp value Cassandra

I'm trying to insert a row in a Cassandra table using the query below

INSERT INTO battery_time_series_by_producer JSON '{"timestamp":1514413581,"customer":"com.fetchcore-cloud.local","stream":"/sw8/sensor/battery","producer":"freight18","data":{"battery_level":1,"is_charging":true,"timestamp":1514413581}}';

and I get the following error

Expected a long or a datestring representation of a timestamp value, but got an Integer: 1514413581

The field timestamp in the table is indeed of the timestamp format. However, how can I convert this to a long given that this is just JSON

My version of Cassandra is 3.11.1

Upvotes: 0

Views: 1663

Answers (1)

sayboras
sayboras

Reputation: 5155

Cassandra will try to parse json object to closest data type possible, e.g. the value 1514413581 is converted to Integer type. If you are giving a larger number, it will be parsed as Long.

Kindly note that that timestamp type is representing a number of milliseconds since the standard base time known as the epoch. The values in your example represent the time in year 1970.

In short, it's either to use string format (e.g. "1514413581") or pass recent timestamp value (which automatically convert to Long later) in your cql statement. Hope it helps.

Upvotes: 1

Related Questions