Hector:hector-core-1.0-5,cassandra-1.1.2
I have a user_event CF created through cqlsh as follows:
user_event(
user_name text,
event_id timeuuid,
event_data text,
PRIMARY KEY(user_name, event_id))
我想在Hector中编写的查询是: 在当前时间之前选择给定用户的最后5个事件。
我的代码如下:
...
{
Composite start = compositeFrom(TimeUUIDUtils.getUniqueTimeUUIDinMillis(),
Composite.ComponentEquality.EQUAL);
Composite end = compositeFrom(TimeUUIDUtils.getUniqueTimeUUIDinMillis(),
Composite.ComponentEquality.GREATER_THAN_EQUAL);
List<HColumn<Composite, String>> cList= dao.getCompositeQueryIterator(key, start, end, stringSerializer);...
}
public static Composite compositeFrom(UUID componentName, Composite.ComponentEquality equalityOp)
{
Composite composite = new Composite();
composite.addComponent(0, componentName, equalityOp);
return composite;
}
我无法弄清楚用于启动和完成复合的操作符和值是什么,这样我就可以获得按时间排序的最后n个事件。 另外,另一个问题是:getUniqueTimeUUIDinMillis()是否适合用于event_id,还是应该在其上创建单独的时间戳列和切片?