1
votes

If I have to predefine all the columns, how do I take the advantage of the variable column key/value structure of cassandra? If I use update table command, it will insert null for all the rows which don't have that column. This is same as relational DB.

For example, for contact column family, I have name, phone, email. I have 100 contacts have all 3 field. Then number 101 contact has skype id which I want to add. If I use insert statement, it won't let me add skypeid since it's not defined in the CF. So I have to run alter statement to change the CF, then all the first 100 contacts will have a null field for each of them.

2
Can you post the commands which you are using? This is true that in cassandra, you can easily insert and update variable number of columns in a row. - Easility
for example, for contact column family, I have name, phone, email. I have 100 contacts have all 3 field. Then number 101 contact has skype id which I want to add. If I use insert statement, it won't let me add skypeid since it's not defined in the CF. So I have to run alter statement to change the CF, then all the first 100 contacts will have a null field for each of them. - icejade
some document said we can model dynamic columns in CQL3 using compositekey. I just don't see how they are related or how that can be done. - icejade

2 Answers

1
votes

The Thrift API can create columns on-the-fly. For example in Astyanax you can insert columns which were not defined in the schema. But this will still leave your first 100 columns effectively with a null value for that column, so there's no real reason to avoid updating the schema and several downsides. This is why CQL enforces "tell the schema about it first."

Now, if you have truly dynamic fields to deal with, you can use collections in CQL. But this is not the case in your example.

1
votes

If I use insert statement, it won't let me add skypeid since it's not defined in the CF. So I have to run alter statement to change the CF, then all the first 100 contacts will have a null field for each of them.

But perhaps not a problem. The DataStax documentation for CQL3 INSERT says

An INSERT writes one or more columns to a record in a Cassandra table atomically and in isolation. No results are returned. You do not have to define all columns, except those that make up the key. Missing columns occupy no space on disk.