Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting timestamp into Cassandra

I have a table created as follows:

CREATE TABLE my_table (
  date text,
  id text,
  time timestamp,
  value text,
  PRIMARY KEY (id));

CREATE INDEX recordings_date_ci ON recordings (date);

I'm able to simply add a new row to the table using the following Node code:

const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['localhost'], keyspace: 'my_keyspace'});

const query = 'INSERT INTO my_table (date, id, time, url) VALUES (?, ?, ?, ?)';
client.execute(query, ['20160901', '0000000000', '2016-09-01 00:00:00+0000', 'random url'], function(err, result) {
  if (err){
    console.log(err);
  }
  console.log('Insert row ended:' + result);
});

However, I get the following error:

'Error: Expected 8 or 0 byte long for date (24)

When I change the timestamp to epoc time:

client.execute(query, ['20160901', '0000000000', 1472688000, 'random url']

I get: d

OverflowError: normalized days too large to fit in a C int

I'm able to insert new rows via cqlsh so I'm probably missing something with the node.js driver.

Any idea?

Thanks

like image 432
Lior Ohana Avatar asked Oct 24 '16 15:10

Lior Ohana


1 Answers

Where you have a string 2016-09-01 00:00:00+0000, instead use new Date('2016-09-01 00:00:00+0000').

like image 145
Peter Lyons Avatar answered Oct 06 '22 08:10

Peter Lyons