1

I want to store snapshots of an object in Apache Cassandra 1.2

Row key is the Object#ID and there will be a column for each snapshot.

--------    latest  --------   v2   -------- v1
id-122      100     --------   50   -------- 66
--------

So column names are created dynamically at runtime.

How to create the previous table in Cassandra 1.2 using CQL3?

Chiron
  • 20,081
  • 17
  • 81
  • 133

2 Answers2

4

You would use the compound primary key feature of CQL3:

CREATE TABLE foo (
  object_id int,
  version int,
  value int,
  PRIMARY KEY (object_id, version));
nickmbailey
  • 3,674
  • 15
  • 14
0

In CQL3, Table schema is fixed. So you can't really get dynamic column names. For that you have to switch to CQL2.

abhi
  • 4,762
  • 4
  • 29
  • 49
  • The schema is fixed, but things like compound keys and collections allow you to do everything you can in Thrift and CQL2, and more. – Theo Feb 06 '13 at 19:56
  • @Theo: Rightly said. But i belief, its not possible to use collection in a handy way, due to the lacking of secondary indexes, and yes please rectify me if i am wrong. That's why for me my choice is still CQL2. – abhi Feb 07 '13 at 05:46
  • `CREATE TABLE example (id1 TEXT, id2 TEXT, value TEXT, PRIMARY KEY (id1, id2))` <-- `id1` is row key, `id2` is column key, `value` is column value. Just like in the Thrift API and CQL2. – Theo Feb 07 '13 at 12:46
  • `CREATE INDEX my_index ON example (id2)` <-- secondary index in CQL3. – Theo Feb 07 '13 at 12:47
  • 4
    I am talking about secondary index on a collection(list,map & set) field, not the normal one. – abhi Feb 08 '13 at 05:26
  • To add columns in CQL3 we have to use `ALTER Table` clause – manuzhang Feb 12 '13 at 09:28