使用复合键插入cassandra列族

时间:2012-06-25 08:15:21

标签: nosql cassandra composite-primary-key hector

我有一个列系列AllLog创建

create column family LogData
  with column_type = 'Standard'
  and comparator = 'CompositeType(org.apache.cassandra.db.marshal.UTF8Type,org.apache.cassandra.db.marshal.UTF8Type)'
  and default_validation_class = 'UTF8Type'
  and key_validation_class = 'CompositeType(UTF8Type,UTF8Type)';

但是当我使用mutator插入时:

    String key0 = "key0";
    String key1 = "key1";

    Composite compositeKey = new Composite();
    compositeKey.addComponent(key0, StringSerializer.get());
    compositeKey.addComponent(key1, StringSerializer.get());

    // add
    mutator.addInsertion(compositeKey, columnFamilyName, HFactory.createColumn("name", "value"));
    mutator.execute();

总是通过例外:

me.prettyprint.hector.api.exceptions.HInvalidRequestException:
InvalidRequestException(why:Not enough bytes to read value of component 0)

请有人帮助我,我在这段代码中的错误在哪里?

1 个答案:

答案 0 :(得分:2)

模式将比较器指定为复合类型,但插入会创建一个包含单个字符串(“name”)的列。