1
votes

I am designing the Column Family for our use case in Cassandra. I am planning to go with Dynamic Column Structure.

Below is my requirement per our use case-

user-id   column1                                        column2                                     column3
123      (Column1-Value  Column1-SchemaName  LMD)       (Column2-Value Column2-SchemaName  LMD)     (Column3-Value  Column3-SchemaName  LMD)

For each user-id, we will be storing column1 and its value and that value will store these three things always-

(Column1-Value   Column1-SchemaName     LMD)

In my above example, I have show only three columns but it might have more columns.

Now I am not sure, how to store these three thing always at a column value level? Should I use composite columns at a column level? if yes, then I am not sure how to make a column family like this in Cassandra.

Column1-value will be in binary, Column1-SchemaName will be String, LMD will be DateType.

This is what I have so far-

create column family USER_DATA
with key_validation_class = 'UTF8Type'
and comparator = 'UTF8Type'
and default_validation_class = 'UTF8Type'
and gc_grace = 86400
and column_metadata = [ {column_name : 'lmd', validation_class : DateType}];

Can anyone help me in designing the column family for this?

2

2 Answers

1
votes

@TechGeeky

Change the comparator to :

comparator = 'CompositeType(ByteType,UTF8Type,DateType)'

ByteType for Column-Value

UTF8Type for Column-SChemaName

DateType for LMD

Be careful though, with this design, querying your data other than by user-id would be hard. Especially you would be able to get slices of columns by providing column data (in bytes), if you know them before hand...

1
votes

I would suggest you use CQL3. If you use Cassandra 1.2+ and CQL3, the following table will result in the partition (row) layout you describe.

CREATE TABLE user_data (
    userid text,
    data bytes,
    schema_name string,
    lmd timestamp,
    PRIMARY KEY (userid, data, schema_name, lmd)
)

You can see the following article for more information on how CQL3 ends up as composite columns under the hood, and makes them much easier to use:
http://www.datastax.com/dev/blog/cql3-for-cassandra-experts