将时间戳插入 Cassandra
Inserting timestamp into Cassandra
我创建了一个 table 如下:
CREATE TABLE my_table (
date text,
id text,
time timestamp,
value text,
PRIMARY KEY (id));
CREATE INDEX recordings_date_ci ON recordings (date);
我可以使用以下节点代码向 table 添加一个新行:
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);
});
但是,我收到以下错误:
'Error: Expected 8 or 0 byte long for date (24)
当我将时间戳更改为 epoc 时间时:
client.execute(query, ['20160901', '0000000000', 1472688000, 'random url']
我得到:
d
OverflowError: normalized days too large to fit in a C int
我可以通过 cqlsh 插入新行,所以我可能遗漏了 node.js 驱动程序的某些内容。
有什么想法吗?
谢谢
如果您有字符串 2016-09-01 00:00:00+0000
,请改用 new Date('2016-09-01 00:00:00+0000')
。
我创建了一个 table 如下:
CREATE TABLE my_table (
date text,
id text,
time timestamp,
value text,
PRIMARY KEY (id));
CREATE INDEX recordings_date_ci ON recordings (date);
我可以使用以下节点代码向 table 添加一个新行:
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);
});
但是,我收到以下错误:
'Error: Expected 8 or 0 byte long for date (24)
当我将时间戳更改为 epoc 时间时:
client.execute(query, ['20160901', '0000000000', 1472688000, 'random url']
我得到: d
OverflowError: normalized days too large to fit in a C int
我可以通过 cqlsh 插入新行,所以我可能遗漏了 node.js 驱动程序的某些内容。
有什么想法吗?
谢谢
如果您有字符串 2016-09-01 00:00:00+0000
,请改用 new Date('2016-09-01 00:00:00+0000')
。