时间戳/日期作为cassandra列族/ hector的键 [英] 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 ?
我的架构和要求如下:(actual 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列族/ hector的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!