Hector是否提供API来支持组合密钥?

时间:2011-09-16 05:33:56

标签: cassandra hector

现在,我必须通过将子键格式化来手动生成复合键。这很丑陋而且效率不高。我想知道Hector是否提供了这样一组API来以更合适的方式处理复合键。

1 个答案:

答案 0 :(得分:5)

是的。

您可以查看DynamicCompositeTest的示例:

https://github.com/rantav/hector/blob/master/core/src/test/java/me/prettyprint/hector/api/beans/DynamicCompositeTest.java

@Test
public void allTypesSerialize() {
    DynamicComposite composite = new DynamicComposite();

    UUID lexUUID = UUID.randomUUID();
    com.eaio.uuid.UUID timeUUID = new com.eaio.uuid.UUID();


    //add all forward comparators
    composite.addComponent(0, "AsciiText", AsciiSerializer.get(), "AsciiType", ComponentEquality.EQUAL);
    composite.addComponent(1, new byte[]{0, 1, 2, 3}, BytesArraySerializer.get(), "BytesType", ComponentEquality.EQUAL);
    composite.addComponent(2, -1, IntegerSerializer.get(), "IntegerType", ComponentEquality.EQUAL);
    composite.addComponent(3,  lexUUID, UUIDSerializer.get(), "LexicalUUIDType", ComponentEquality.EQUAL);
    composite.addComponent(4, -1l, LongSerializer.get(), "LongType", ComponentEquality.EQUAL);
    composite.addComponent(5, timeUUID, TimeUUIDSerializer.get(), "TimeUUIDType", ComponentEquality.EQUAL);
    composite.addComponent(6, "UTF8Text", StringSerializer.get(), "UTF8Type", ComponentEquality.EQUAL);
    composite.addComponent(7,  lexUUID, UUIDSerializer.get(), "UUIDType", ComponentEquality.EQUAL);