Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 621
tnk_peka Avatar asked Nov 04 '22 21:11

tnk_peka


1 Answers

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

like image 173
libjack Avatar answered Nov 15 '22 12:11

libjack