本文介绍了如何定义列族的复合键,然后使用Hector引用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到样本?

我的大部分代码使用ColumnFamilyTemplate对数据记录做CRUD,见下文。一旦我定义了复合键,我仍然可以使用ColumnFamilyTemplate来访问我的具有复合键的数据?

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()));


推荐答案

CRUD上的记录; CompositeType(或DynamicCompositeType)只是另一个类型(例如类似于UUID),它具有对应的串行器(CompositeSerializer)。所以,你的例子可能会变成:

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:

private static final ColumnFamilyTemplate<Composite, String> template = 
new ThriftColumnFamilyTemplate<Composite, String>(
    Bootstrap.keyspace, 
    "User", 
    CompositeSerializer.get(), 
    StringSerializer.get(),
    HFactory.createMutator(Bootstrap.keyspace, CompositeSerializer.get()));

只有额外的功能是在使用模板之前创建Composite(假设组合UUID& Long)

Only extra would be to create the Composite before using template (assume composite of UUID & Long):

Composite key = new Composite();
key.addComponent(someUUID, UUIDSerializer.get());
key.addComponent(someLong, LongSerializer,get());
ColumnFamilyResult<Composite,String> result = template.queryColumns(key);

获取结果时,一种方法是获取密钥的组件:

When fetching results, one way to get the components of the key:

myUUID = result.getKey().get(0, UUIDSerializer.get());
myLong = result.getKey().get(1, LongSerializer,get());

这篇关于如何定义列族的复合键,然后使用Hector引用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 22:38