====15 Feb 2012, by Bright Zheng (IT进行时)====
A keyspace is the first dimension of the Cassandra hash, and is the container for the ColumnFamilies. Keyspaces are of roughly the same granularity as a schema or database (i.e. a logical collection of tables) in the RDBMS world. They are the configuration and management point for column families, and is also the structure on which batch inserts are applied. In most cases you will have one Keyspace for an application.
[default@unknown] drop keyspace Tutorial; 876ee520-571f-11e1-0000-242d50cf1ffd Waiting for schema agreement... ... schemas agree across the cluster [default@unknown] create keyspace Tutorial ... with strategy_options = [{replication_factor:1}] ... and placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'; WARNING: [{}] strategy_options syntax is deprecated, please use {} 8daea060-571f-11e1-0000-242d50cf1ffd Waiting for schema agreement... ... schemas agree across the cluster [default@unknown] use Tutorial; Authenticated to keyspace: Tutorial [default@Tutorial] |
A column family is a container for columns, something like the TABLE in a relational system.
Model representation:
ColumnFamily |
|
key |
list |
binary |
1 .. * Columns |
Data representation:
ColumnFamily |
|||
key |
Columns |
||
1 |
name |
value |
timestamp |
|
"firstname" |
"Ronald" |
1270073054 |
|
"lastname" |
"Mathies" |
1270073054 |
|
"birthday" |
"01/01/1978" |
1270073054 |
2 |
name |
value |
timestamp |
|
"firstname" |
"John" |
1270084021 |
|
"lastname" |
"Steward" |
1270084021 |
|
"birthday" |
"01/01/1982" |
1270084021 |
[default@Tutorial] drop column family StateCity; StateCity not found in current keyspace. [default@Tutorial] create column family StateCity ... with comparator = LongType ... and default_validation_class = 'UTF8Type' ... and key_validation_class = 'UTF8Type'; d3cfa8f0-571f-11e1-0000-242d50cf1ffd Waiting for schema agreement... ... schemas agree across the cluster [default@Tutorial] |
Where:
1. Comparator is used to validate and compare/sort Column names in the CF. It has following supported types:
Type |
Description |
BytesType |
Simple non-validating byte comparison (Default) |
AsciiType |
Similar to BytesType, but validates that input is US-ASCII |
UTF8Type |
UTF-8 encoded string comparison |
LongType |
Compares values as 64 bit longs |
LexicalUUIDType |
128 bit UUID compared by byte value |
TimeUUIDType |
Timestamp compared 128 bit version 1 UUID |
Note:
A Column consists of a name, value and a timestamp.
Model representation:
Column |
|
name |
Binary |
value |
Binary |
timestamp |
i64 |
Data representation:
Column |
||
name |
value |
timestamp |
"firstname" |
"Ronald" |
1270073054 |
N/A
A SuperColumn is very similar to a ColumnFamily, it consists of a key and a list of Columns.
Model representation:
SuperColumn |
|
key |
list |
binary |
1 .. * Columns |
Data representation:
SuperColumn |
|||
key |
Columns |
||
1 |
name |
value |
timestamp |
|
"firstname" |
"Ronald" |
1270073054 |
|
"lastname" |
"Mathies" |
1270073054 |
|
"birthday" |
"01/01/1978" |
1270073054 |
2 |
name |
value |
timestamp |
|
"firstname" |
"John" |
1270084021 |
|
"lastname" |
"Steward" |
1270084021 |
|
"birthday" |
"01/01/1982" |
1270084021 |
The only difference to ColumnFamily is the usage. A SuperColumn is used within a ColumnFamily. So it adds an extra layer in your data structure, instead of having only a row which consists of a key and a list of columns. We can now have a row which consists of a key and a list of super columns which by itself has keys and per key a list of columns.
Once the ColumnFamily uses SuperColumn, the column type must be “Super”. By default the column type is “Standard” which means common Column.
To be added here!
Please refer to http://wiki.apache.org/cassandra/API for more.