Apache Cassandra Learning Step by Step (2): Core Concepts

====15 Feb 2012, by Bright Zheng (IT进行时)====

3. Core Concepts

3.1.  Keyspace

3.1.1.  Intro

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.

3.1.2. CLI

[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]

3.2. Column Family

3.2.1. Intro

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

3.2.2. CLI

[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:

  1. The above types are changeable subject to different versions.
  2. It is also valid to specify the fully-qualified class name to a customized class that extends org.apache.Cassandra.db.marshal.AbstractType.

3.3. Column

3.3.1. Intro

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

3.3.2. CLI

N/A

3.4. SuperColumn

3.4.1. Intro

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.

3.4.2. CLI (TODO)

To be added here!

3.5. Others?

Please refer to http://wiki.apache.org/cassandra/API for more.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值