Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra Static Column design [closed]

How are static columns stored internally in cassandra? Can someone please post an example discussing the design implementation of static column in cassandra?

like image 450
Sachin Janani Avatar asked Feb 27 '15 14:02

Sachin Janani


People also ask

What is 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.

Is Cassandra column family?

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.

What is a static column?

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.


1 Answers

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

like image 174
RussS Avatar answered Sep 20 '22 10:09

RussS