2011-09-16 42 views
3

現在,我必須通過將子鍵一起格式化來手動生成組合鍵。這是醜陋的,沒有效率。我想知道Hector是否提供了這樣一組API以更體面的方式處理複合鍵。Hector是否提供API來支持組合鍵?

回答

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

的感謝!最重要的是,這個列族應該是什麼模式? – tom

+0

因此,因爲它被稱爲DynamicComposite,我們無法在模式上「描述」它,對嗎? – tom

+0

東西liek此: 創建列家族StateNpaIndexDynamic 與比較= 'DynamicCompositeType性(s => UTF8Type,L => LongType)' 和key_validation_class = 'UTF8Type' 和default_validation_class = 'UTF8Type'; – Patricio

相關問題