cassandra 无法使用时间戳查询数据库

afdcj2ne  于 2022-11-05  发布在  Cassandra
关注(0)|答案(1)|浏览(158)

我有这张table

user_authentication_token (
    token_id uuid,
    user_id uuid,
    email text,
    expiration_time timestamp,
    is_sign_up boolean,
    PRIMARY KEY ((token_id, user_id, email, expiration_time))

我在表中有这些数据

token_id                             | user_id                              | email                   | expiration_time                 | is_sign_up
--------------------------------------+--------------------------------------+-------------------------+---------------------------------+------------
 98b0456a-05b2-4aca-a6c7-6a1f382e19aa | b284d51d-efbb-4204-b342-a2486029a5c5 | manu.chadha@hotmail.com | 2018-09-01 09:40:59.634000+0000 |       True

但我无法查询。
InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to coerce '2018-09-01 09:40:59.634000+0000' to a formatted date (long)"
错误-InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to coerce '2018-09-01 09:40:59.634000+0000' to a formatted date (long)"
我做错了什么?
我使用Cassandra Java Datastax驱动程序和以下代码插入了该行

def insertValues(tableName:String, model:UserToken):Insert = {
    QueryBuilder.insertInto(tableName).value("token_id",model.tokenId) 
      .value("email",model.email)
      .value("user_id",model.userId)
      .value("expiration_time",model.expirationTime.getMillis())
      .value("is_sign_up",model.isSignUp)
      .ifNotExists(); }}

有趣的是,时间戳存储为long,但cqlsh以可读格式显示它。可能我需要再次将其转换为long,但我该怎么做呢?

6rqinv9w

6rqinv9w1#

您的时间戳不应超过毫秒:

select * from user_authentication_token
where token_id=98b0456a-05b2-4aca-a6c7-6a1f382e19aa
and user_id=b284d51d-efbb-4204-b342-a2486029a5c5
and email='manu.chadha@hotmail.com'
and expiration_time='2018-09-01 09:40:59.634+0000'; // removed extra precision

**更新:**添加了由Manu Chadha发现的时区偏移量。

相关问题