How are static columns stored internally in cassandra? Can someone please post an example discussing the design implementation of static column in cassandra?
Static column: In Cassandra Query Language (CQL) it is a special column that is shared by all the rows of a partition. the static column is very useful when we want to share a column with a single value. In Cassandra query language static columns are only static within a given partition.
However, in Cassandra, columns are not defined (although column families are), so it's possible to add any column to a column family at any time. Cassandra does not force all columns on individual rows. In Cassandra, a table can be defined as a super column family or can contain columns.
Static column values are shared among the rows in the partition. In a table that uses clustering columns, non-clustering columns can be declared static in the table definition. Static columns are only static within a given partition.
Why don't we take a look at the structure of a table with static columns on disk and find out?
cqlsh:test> CREATE TABLE test (k int, v int, s int static, d int, PRIMARY KEY(k,v))
cqlsh:test> INSERT INTO test (k, v, s, d) VALUES ( 1, 1 ,20, 1 );
cqlsh:test> INSERT INTO test (k, v, s, d) VALUES ( 1, 3 ,21, 2 );
cqlsh:test> INSERT INTO test (k, v, s, d) VALUES ( 1, 2 ,21, 2 );
Exit out of C* and run nodetool flush
to make our sstables. Run sstable2json
on the .db file that was created in the data directory.
[
{"key": "1", <--- K=1 Partition
"cells": [[":s","21",1425050917842350], <---- Our Static Column
["1:","",1425050906896717], < --- C=1 row
["1:d","1",1425050906896717], < --- C=1, D=1 value
["2:","",1425050917842350], < --- C=2 row
["2:d","2",1425050917842350], < --- C=2, D=2 value
["3:","",1425050912874025], <--- C=3 Row
["3:d","2",1425050912874025]]} <--- C=3, D=2 Value
]
You can see that in Cassandra this static column is held in a cell with the title "Blank:ColumnName" at the very beginning of our partition. Unlike all the other cells there is no information about c(our clustering column) in the cell name, so all values of c will still modify the same static column s
For more details on why this is, check out the JIRA at https://issues.apache.org/jira/browse/CASSANDRA-6561 and the blog post at http://www.datastax.com/dev/blog/cql-in-2-0-6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With