0
votes

Is it possible to insert a row of following format in cassandra using hector api:

rowkey1 ==>     "Column name1":{"item1","item2","item3"}
                "Column name2":{"item11","item22","item33"}
                "Column name3":{"item111","item222","item333"}

rowkey2 ==>     "Column name1-a":{"item1","item2","item3"}
                "Column name2-b":{"item11","item22","item33"}
                "Column name3-c":{"item111","item222","item333"}

i.e each column will consist of: column_name, multiple column value i.e. A column will consist of Column name and its value will consist of multiple thing like {'item title','item price','about item'} .Columns name and kind of column value are dynamic, different row might have different columns with different number and different kind of values.

I was thinking of doing somthing like: column name will be String and column value will be some class object with required property. Is it good? The idea behind is that it will contain every thing in same column and in single call to column will give all multiple values. Using multiple column might increase the work of reading multiple column.

Editing and reading record should not be a problem as i think. I am using hector core API not CQL as columns are dynamic.

Any suggestion or solutions ??

2

2 Answers

3
votes

It sounds like what you want to use is a CQL Map. Hector offers poor support for CQL; use the DataStax Java Driver instead.

The claim that CQL does not support dynamic columns is an unfortunately common misunderstanding.

0
votes

By definition Cassandra is a key-value database, so the model that your looking for doesn't fit with the philosophy of Cassandra. The column name has to be unique, so if you made:

create columnfamily demo WITH comparator = UTF8Type AND key_validation_class = UTF8Type AND default_validation_class=UTF8Type;
 set demo['1']['column1'] = 'value';
 set demo['1']['column1'] = 'value2';

When you perform a get:

 GET demo['1'];
=> (column=column1, value=value2, timestamp=1373438507059000)

I suggest to create two column familys with the same structure, so you can have the same column name in both column familys but store a different column value in each one. With this approach you can edit the columns independently.