---
title: "Apache Cassandra Learning Step by Step (2): Core Concepts"
author: "itstarting"
date: "2012-02-15T21:04:20Z"
tags: []
categories: ["互联网"]
slug: "apache-cassandra-learning-step-by-step-2-core-concepts"
draft: false
lastmod: "2012-02-16T16:54:36Z"
id: 1407571
url: "https://itstarting.iteye.com/blog/1407571"
---

====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](http://wiki.apache.org/cassandra/API) for more.