Cassandra之中一共包含下面5种Key:

  1. Primary Key
  2. Partition Key
  3. Composite Key
  4. Compound Key
  5. Clustering Key
首先,Primary key 是用来获取某一行的数据, 可以是一列或者多列(复合列 composite)
Primary = Partition Key  + [Clustering Key] (Clustering Key 可选)
Clustering keys 包括下面两种情况:
(1) composite key
(2) compound key
 
1
2
3
4
5
6
7
8
9
10
11
12
-- 一列
create table stackoverflow (
      key text PRIMARY KEY,
      data text      
);
-- 复合列
create table stackoverflow (
      key_part_one text,
      key_part_two int,
      data text,
      PRIMARY KEY(key_part_one, key_part_two)      
  );

在上面复合列的table之中,全称:  Composite Primary Key
并且:
(1) key_part_one  –> partition key
(2) key_part_two  –> clustering key
注意: partition key, clustering key 都可以是复合列。
Partition Key : Cassandra会对partition key 做一个hash计算,并自己决定将这一条记录放在哪个node
Partition Key的设计,可以完全的借用MySQL的主键。

Cassandra会给每一行数据一个timestamp,如果有多行数据,Cassandra会取时间最新的数据返回!

Clustering Key :   主要用于进行Range Query. 并且使用的时候需要按照建表顺序进行提供信息!

参考下面代码:
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- 创建表
-- 注意state 这个field
CREATE TABLE users (
  mainland text,
  state text,
  uid int,
  name text,
  zip int,
  PRIMARY KEY ((mainland), state, uid)
)
 
 
-- 插入一些值
insert into users (mainland, state, uid, name, zip)
    VALUES ( 'northamerica', 'washington', 1, 'john', 98100);
xxxx more
insert into users (mainland, state, uid, name, zip)
    VALUES ( 'southamerica', 'argentina', 6, 'alex', 10840);

有效的查询:

 
1
select * from users where mainland = 'northamerica' and state > 'ca' and state < 'ny';

本质是先node上查找后,然后range筛选!

 

Cassandra key说明——Cassandra 整体数据可以理解成一个巨大的嵌套的Map Map<RowKey, SortedMap<ColumnKey, ColumnValue>>的更多相关文章

  1. Cassandra 的数据存储结构——本质是SortedMap<RowKey, SortedMap<ColumnKey, ColumnValue>>

    Cassandra 的数据存储结构 Cassandra 的数据模型是基于列族(Column Family)的四维或五维模型.它借鉴了 Amazon 的 Dynamo 和 Google's BigTab ...

  2. Cassandra存储time series类型数据时的内部数据结构?

        因为我一直想用Cassandra来存储我们的数字电表中的数据,按照之前的文章(getting-started-time-series-data-modeling)的介绍,Cassandra真的 ...

  3. cassandra mongodb选择——cassandra:分布式扩展好,写性能强,以及可以预料的查询;mongodb:非事务,支持复杂查询,但是不适合报表

    Of course, like any technology MongoDB has its strengths and weaknesses. MongoDB is designed for OLT ...

  4. 谈谈Delph中的类和对象2---类可以理解成一种特殊的数据结构、类型转换

    三.类可以理解成一种特殊的数据结构 我们知道数据类型可以进行强制类型转换,类既然可以理解成一种数据类型,那么它也应该可以进行类型转换.比如下面代码为一个按钮(Button1)的单击事件 procedu ...

  5. Cassandra使用pycassa批量导入数据

    本周接手了一个Cassandra系统的维护工作,有一项是需要将应用方的数据导入我们维护的Cassandra集群,并且为应用方提供HTTP的方式访问服务.这是我第一次接触KV系统,原来只是走马观花似的看 ...

  6. cassandra权威指南读书笔记--数据建模

    没有join操作.有轻量级事务和批处理,但是没有外键等.反规范化.3.0支持物化视图,允许在一个表上创建数据的多个物化视图.使用cassandra要从查询入手,而不是先从数据模型开始.先对查询建模,然 ...

  7. Cassandra Demo--Python操作cassandra

    ================================================================ 创建keyspace和table CREATE KEYSPACE ex ...

  8. R︱高效数据操作——data.table包(实战心得、dplyr对比、key灵活用法、数据合并)

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 由于业务中接触的数据量很大,于是不得不转战开始 ...

  9. Cassandra 学习七 cassandra研究

    https://www.cnblogs.com/bonelee/p/6306079.html Allow filtering: 如果你的查询条件里,有一个是根据索引查询,那其它非索引非主键字段,可以通 ...

随机推荐

  1. pip安装lxml报错 Fatal error in launcher: Unable to create process using '"c:\users\administrator\appdata\local\programs\python\python36\python.exe" "C:\Users\Administrator\AppData\L

    pip install lxml 安装报错 E:\apollo\spider_code>Fatal error in launcher: Unable to create process usi ...

  2. MySQL数据库(5)- pymysql的使用、索引

    一.pymysql模块的使用 1.pymysql的下载和使用 之前我们都是通过MySQL自带的命令行客户端工具mysql来操作数据库,那如何在python程序中操作数据库呢?这就需要用到pymysql ...

  3. docker的安装以及jdk和tomcat的环境配置

    准备工作:需要Linux kernel 3.8支持查看linux内核的版本:root@ubuntu-dev:~# cat /proc/version查看linux版本:root@ubuntu-dev: ...

  4. rest字符串匹配模式-初次实现方案

    一般的rest访问的路径如同这样的路径 http://localhost:8080/AppName/{class}/{method}/{param1}/{param2}... rest的方法分:POS ...

  5. java sql解析

    https://github.com/JSQLParser/JSqlParser 淘宝博客:http://www.searchtb.com/category/%E6%90%9C%E7%B4%A2%E5 ...

  6. java byte为何范围是-128~127

    从我们接触Java的时候,就被告知基础类型byte是一个字节,占8位,表示的范围是-128~127.那么为什么会这个范围呢?   咱们先回顾一下计算机基础: 1. 在计算机内部数据的存储和运算都采用二 ...

  7. $python正则表达式系列(6)——"或"表达式的用法

    import re s1 = u'距离地铁5号线189米' s2 = u'距离地铁5号线(环中线)189米' s3 = u'距离地铁5号线(环中线)189米' p1 = re.compile(u'号线 ...

  8. js使用经验之谈

    1.  js 对象,先有的起作用.CSS属性,后有的起作用. 2. 方法中使用submit提交表单,如果提交后面还有代码需要执行,不能保证顺序.例如,提交后关闭页面,很可能会在提交前关闭页面,导致提交 ...

  9. 基于HTML5和SVG的手机菜单动画

    在线演示 本地下载

  10. <nginx+PHP>nginx环境下配置支持php7

    [root@redhat7 ~]# wget http://am1.php.net/get/php-7.1.2.tar.gz/from/this/mirror [root@redhat7 ~]# ta ...