Astyanax 通过其AnnotatedCompositeSerializer
. 我有一个具有 3 字段复合列名称的列族,类似于此示例,改编自Astyanax 的文档(这些列实际上不是sessionId
and 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
并手动序列化开始和结束吗?