时间戳/日期作为 cassandra 列族/赫克托的键 [英] Timestamp / date as key for cassandra column family / hector
问题描述
我必须创建和查询复合键为 [timestamp,long] 的列族.还,查询时我想触发时间戳范围查询(例如 xxx 和 yyy 之间的时间戳)这可能吗?
I have to create and query a column family with composite key as [timestamp,long]. Also, while querying I want to fire range query for timestamp (like timestamp between xxx and yyy) Is this possible ?
目前我正在做一些非常有趣的事情(我知道这是不正确的).我为给定的范围创建带有时间戳字符串的键,并与 long 连接.
Currently I am doing something really funny (Which I know its not correct). I create keys with timestamp string for given range and concatenate with long.
like ,
1254345345435-1234
3423432423432-1234
1231231231231-9999
并将一组密钥传递给 hector api.(所以如果我有 1 个月的日期范围并且我想要每分钟的数据,我创建 30 * 24 * 60 * [二级键的数量 - 长])
and pass set of keys to hector api. (so if i have date range for 1 month and I want every minute data, i create 30 * 24 * 60 * [number of secondary key - long])
我可以用复合键解决连接问题.但查询部分是我想要理解的.
I can solve concatenation issue with composite key. But query part is what I am trying to understand.
据我所知,当我们使用 RandomPartitioner 时,我们无法真正基于范围进行查询,因为键是 MD5 校验和.这种用例的理想设计是什么?
As far as I understood, As we are using RandomPartitioner we cannot really query based on range as keys are MD5 checksum. Whats ideal design for this kind of use case ?
我的架构和要求如下:(实际csh)
my schema and requirements are as follows : (actual csh)
CREATE TABLE report(
ts timestamp,
user_id long,
svc1 long,
svc2 long,
svc3 long,
PRIMARY KEY(ts, user_id));
select from report where ts between (123445345435 and 32423423424) and user_id is in (123,567,987)
推荐答案
您不能对复合键的第一个组件进行范围查询.相反,您应该编写一个标记值,例如daystamp(当天午夜的unix 纪元)作为键,然后将复合列写入timestamp:long.通过这种方式,您可以提供构成您的范围的键,并在复合列的时间戳组件上进行切片.
You cannot do range queries on the first component of a composite key. Instead, you should write a sentinel value such as a daystamp (the unix epoch at midnight on the current day) as the key, then write a composite column as timestamp:long. This way you can provide the keys that comprise your range, and slice on the timestamp component of the composite column.
这篇关于时间戳/日期作为 cassandra 列族/赫克托的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!