Does Hector provide APIs to support composite key?

我的梦境 提交于 2019-12-07 11:54:47

问题


Right now, I have to manually generate the composite key by formatting the subkeys together. It's ugly and not efficient. I wonder if Hector provides such set of APIs to handle composite keys in a more decent way.


回答1:


yes it does.

You can look at DynamicCompositeTest for examples:

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


来源:https://stackoverflow.com/questions/7440530/does-hector-provide-apis-to-support-composite-key

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!