Java 卡桑德拉时间戳不准确?
我正在使用cassandra maven插件和maven failsafe为处理cassandra相关操作的类执行TestNG集成测试 试图找出为什么我对timestamp类型的列的查询总是失败;我注意到一些奇怪的事情。起初,我使用的日期作为参数,从Cassandra检索到的日期看起来是一样的,我将它们格式化为字符串进行比较 但当我以毫秒为单位进行比较时,我注意到Cassandra日期比我用于查询的日期提前了约1000毫秒 然后我直接使用毫秒设置行的时间戳值,但是Cassandra再次返回了一个带有额外毫秒的日期 问题是,这是一个已知的bug吗 现在我将使用一个字符串或日期的长表示来修复这个问题;但我想知道发生了什么 谢谢 编辑:我正在使用Windows 8.1运行测试 以下是加载到嵌入式Cassandra的我的(经过一定程度清理的)数据集文件:Java 卡桑德拉时间戳不准确?,java,cassandra,timestamp,cql,Java,Cassandra,Timestamp,Cql,我正在使用cassandra maven插件和maven failsafe为处理cassandra相关操作的类执行TestNG集成测试 试图找出为什么我对timestamp类型的列的查询总是失败;我注意到一些奇怪的事情。起初,我使用的日期作为参数,从Cassandra检索到的日期看起来是一样的,我将它们格式化为字符串进行比较 但当我以毫秒为单位进行比较时,我注意到Cassandra日期比我用于查询的日期提前了约1000毫秒 然后我直接使用毫秒设置行的时间戳值,但是Cassandra再次返回了一个
CREATE KEYSPACE IF NOT EXISTS analytics WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': 1 };
CREATE TABLE IF NOT EXISTS analytics.events (id text, name text, start_time timestamp, end_time timestamp, parameters map<text,text>, PRIMARY KEY (id));
CREATE TABLE IF NOT EXISTS analytics.errors (id text, message text, time timestamp, parameters map<text,text>, PRIMARY KEY (id, time));
CREATE TABLE IF NOT EXISTS analytics.reports (name text, time timestamp, period int, data blob, PRIMARY KEY (name, period));
CREATE TABLE IF NOT EXISTS analytics.user_preferences (company_id text, user_principal text, opted_in boolean, PRIMARY KEY (company_id, user_principal));
CREATE INDEX IF NOT EXISTS event_name ON analytics.events (name);
CREATE INDEX IF NOT EXISTS report_time ON analytics.reports (time);
INSERT INTO analytics.user_preferences (company_id, user_principal, opted_in) VALUES ('company1', 'user1', true);
INSERT INTO analytics.user_preferences (company_id, user_principal, opted_in) VALUES ('company3', 'user3', false);
INSERT INTO analytics.reports (name, time, period, data) VALUES ('com.example.SomeReport1', null, 3, null);
INSERT INTO analytics.reports (name, time, period, data) VALUES ('com.example.SomeReport2', 1296691200000, 1, null);
当我用row.getDate(“time”)获取时间字段时,它会有那些额外的毫秒。查看您的模式和插入/读取查询(如果需要,经过净化)可能会有所帮助,以便有人可以尝试重现该行为。可能是时钟偏移或时间戳精度差异?您使用哪个操作系统进行测试?编辑以澄清您提出的问题。感谢您的回复。我无法重现您的问题。getDate(“时间”)。getTime()返回1296691200000(这是预期值)。您使用的是哪个Cassandra版本和驱动程序版本?
SELECT * FROM analytics.reports WHERE name = ? AND period = ? AND time = ? LIMIT 1;