Does Hector provide APIs to support composite key?
Asked Answered
P

1

3

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.

Planetary answered 16/9, 2011 at 5:33 Comment(0)
S
5

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);
Statement answered 18/9, 2011 at 17:41 Comment(3)
thanks! on top of that, what the schema should look like for such column family?Planetary
So since it's called DynamicComposite, there is nothing we can do on schema to "describe" it, is that right?Planetary
Something liek this: create column family StateNpaIndexDynamic with comparator = 'DynamicCompositeType(s=>UTF8Type,l=>LongType)' and key_validation_class = 'UTF8Type' and default_validation_class = 'UTF8Type';Statement

© 2022 - 2024 — McMap. All rights reserved.