tnk_peka
tnk_peka

Reputation: 1535

Insert cassandra column family with composite key

I have a column family AllLog create that

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

but when I use mutator to insert :

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

always through exception:

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

Please some one help me, where is my mistake in this code?

Upvotes: 5

Views: 2126

Answers (1)

libjack
libjack

Reputation: 6443

The schema specifies comparator as a Composite type, yet the insertion creates a column with a single string ("name").

Upvotes: 2

Related Questions