如何为列族定义复合键,然后使用 Hector 引用它?
我在哪里可以找到这方面的样本?
我的大部分代码使用 ColumnFamilyTemplate 对数据记录进行 CRUD,请参见下文。定义复合键后,我是否仍然可以使用 ColumnFamilyTemplate 来访问具有复合键的数据?
private static final ColumnFamilyTemplate<UUID, String> template =
new ThriftColumnFamilyTemplate<UUID, String>(
Bootstrap.keyspace,
"User",
UUIDSerializer.get(),
StringSerializer.get(),
HFactory.createMutator(Bootstrap.keyspace, UUIDSerializer.get()));
where can I find samples for this?
Most of my code using ColumnFamilyTemplate to do CRUD on the data records, see below. Once I have the composite key defined, can I still use ColumnFamilyTemplate to access my data having composite keys?
private static final ColumnFamilyTemplate<UUID, String> template =
new ThriftColumnFamilyTemplate<UUID, String>(
Bootstrap.keyspace,
"User",
UUIDSerializer.get(),
StringSerializer.get(),
HFactory.createMutator(Bootstrap.keyspace, UUIDSerializer.get()));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用哪个 API 对记录执行 CRUD 并不重要; CompositeType(或DynamicCompositeType)只是另一种类型(例如类似于UUID),它具有相应的序列化器(CompositeSerializer)。因此,您的示例可能会变成:
唯一的额外方法是在使用模板之前创建复合体(假设 UUID 和长整型的复合体):
在获取结果时,获取密钥组件的一种方法是:
It shouldn't matter which API you use to do the CRUD on the records; CompositeType (or DynamicCompositeType) is just another type (e.g. similar to UUID) which has a corresponding serializer (CompositeSerializer). So, your example might become:
Only extra would be to create the Composite before using template (assume composite of UUID & Long):
When fetching results, one way to get the components of the key:
如果定义复合键,还需要告诉 Cassandra (>0.8.1) 使用 CompositeType 作为比较器。下面是一个完整的示例,从定义 CompositeType 架构开始到对范围查询进行编程:
http://randomizedsort.blogspot.com/2011/11/cassandra -range-query-using.html
If you define a composite key, you also need to tell Cassandra (>0.8.1) to use CompositeType as the comparator. Here is a complete example starting from defining CompositeType schema to programming a range query:
http://randomizedsort.blogspot.com/2011/11/cassandra-range-query-using.html