Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple columns in Cassandra tables

Tags:

cassandra

cql3

I am wondering what happens when there are multiple Non-PK columns in a table. I've read this example: http://johnsanda.blogspot.co.uk/2012/10/why-i-am-ready-to-move-to-cql-for.html

Which shows that with single column:

CREATE TABLE raw_metrics (
schedule_id int,
time timestamp,
value double,
PRIMARY KEY (schedule_id, time)
);

We get:

enter image description here

Now I wonder what happens when we have two columns:

CREATE TABLE raw_metrics (
schedule_id int,
time timestamp,
value1 double,
value2 int,
PRIMARY KEY (schedule_id, time)
);

Are we going to end up with something like:

row key  columns...
123      1339707619:"value1" | 1339707679:"value2" | 1339707784:"value2"
...

or rather:

row key  columns...
123      1339707619:"value1":"value2" | 1339707679:"value1":"value2" | 1339707784:"value1""value2"
...

etc. I guess what I am asking is if this is going to be a sparse table given that I only insert "value1" or "value2" at a time.

In such situations if I want to store more columns (one per each type, eg. double, int, date, etc) would it be better perhaps to have separate tables rather than storing everything in a single table?

like image 713
datageek Avatar asked Nov 13 '22 06:11

datageek


1 Answers

This post might help in explaining what is happening when composite keys are created: Cassandra Composite Columns - How are CompositeTypes chosen?

So essentially the table will look in the following way:

row key  columns...
123      1339707619:"value1" | 1339707679:"value2" | 1339707784:"value2"

See also reference to secondary indexes: http://wiki.apache.org/cassandra/SecondaryIndexes

like image 69
Datageek Avatar answered Nov 15 '22 14:11

Datageek