【问题标题】:Is it possible to insert epoch time in cassandra?是否可以在 cassandra 中插入纪元时间?
【发布时间】:2015-12-16 20:57:07
【问题描述】:

表模式:

CREATE TABLE student(
name text,
id int,
class int,
logintime timeuuid,
subject text
PRIMARY KEY ((cust_sub_id, group_id), level, eventtime));

在学生表中插入数据时:

INSERT INTO student(name, id, class, logintime, subject) VALUES ( 'xyz', 10, 12, 242aa080-9e6f-11e5-b62b-903c9927ffc2, 'maths');

它工作正常。 但是可以在cassandra表中插入epochtime/datetime而不是uuid并自动保存为uuid格式吗?

类似:

INSERT INTO student(name, id, class, logintime, subject) VALUES ( 'xyz', 10, 12, 1449663555, 'maths');

如果不可能,那么如何在 Scala 中将 epochtime 转换为 uuid?

或者如何修改现有的uuid增加1天的意思是[exitingDate + 1.day]??

【问题讨论】:

    标签: java scala cassandra


    【解决方案1】:

    您可以为此使用timeuuid 数据类型。它看起来和味道都像常规 UUID,但由两部分组成:时间和特定于节点的随机数据。它可以像这样使用:

    INSERT INTO student(name, id, class, logintime, subject) VALUES ( 'xyz', 10, 12, now(), 'maths');
    

    Yo 可以使用 dateOf() 函数提取 TimeUUID 的时间部分:

    SELECT dateOf(logintime) from student where name='xyz';
    

    顺便说一句,还有writetime() 函数可以应用于任何(非PK)列值以获取实际的列写入时间戳。

    【讨论】:

      猜你喜欢
      • 2015-09-05
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多