【发布时间】:2013-10-09 15:36:28
【问题描述】:
Astyanax 通过其AnnotatedCompositeSerializer 支持 Cassandra 中的复合列。我有一个具有 3 字段复合列名称的列族,类似于此示例,改编自 Astyanax's documentation(这些列实际上不是 sessionId 和 token,假装它们是为了论证):
// Annotated composite class
public class SessionEvent {
@Component(ordinal=0) UUID sessionId;
@Component(ordinal=1) UUID token;
@Component(ordinal=2) UUID timestamp;
public SessionEvent() { }
}
static AnnotatedCompositeSerializer<SessionEvent> eventSerializer
= new AnnotatedCompositeSerializer<>(SessionEvent.class);
static ColumnFamily<String, SessionEvent> CF_SESSION_EVENTS
= new ColumnFamily<>("SessionEvents",
StringSerializer.get(), eventSerializer);
// Querying cassandra for a column slice on one prefix, but we want two!
OperationResult<ColumnList<SessionEvent>> result = keyspace.prepareQuery(CF_SESSION_EVENTS)
.getKey("UserId1")
.withColumnRange(eventSerializer.buildRange()
.withPrefix("SessionId1")
.build())
.execute();
问题是:我想查询前缀中包含两个复合列(在本例中为sessionId 和token)的所有列,而不仅仅是一个,而且是所有时间戳,而不仅仅是在一个范围内.这显然可以使用 CQL3 轻松实现,但我被困在 Cassandra 1.0.x 上,找不到 Astyanax 可以接受的方法(通过两次调用 withPrefix(UUID) 或将复合数据结构传递给它)。
有没有办法用 Astyanax 做到这一点?我可以以某种方式使用基本的RangeBuilder 并手动序列化开始和结束吗?
【问题讨论】: