我是NoSQL的新手;所以,我试图理解一些我可以从我研究过的数十个来源中得到的Cassandra概念。
答案 0 :(得分:4)
一个常见的误解是CQL不支持动态列或宽行。相反,CQL旨在支持您可以使用Thrift模型执行的所有操作,但使其更容易,更易于访问。
让我们看看下面的cql表。
CREATE TABLE data (
sensor_id int,
collected_at timestamp,
volts float,
PRIMARY KEY (sensor_id, collected_at)
);
并插入一些数据
sensor_id | collected_at | volts
----------+--------------------------+-------
1 | 2013-06-05 15:11:00-0500 | 3.1
1 | 2013-06-05 15:11:10-0500 | 4.3
1 | 2013-06-05 15:11:20-0500 | 5.7
2 | 2013-06-05 15:11:00-0500 | 3.2
3 | 2013-06-05 15:11:00-0500 | 3.3
3 | 2013-06-05 15:11:10-0500 | 4.3
此处,群集列collected_at
类似于Thrift动态列。(Q.1)
如果我们看一下这个表的内部结构
RowKey: 1
=> (cell=2013-06-05 15:11:00-0500, value=3.1, timestamp=1370463146717000)
=> (cell=2013-06-05 15:11:10-0500, value=4.3, timestamp=1370463282090000)
=> (cell=2013-06-05 15:11:20-0500, value=5.7, timestamp=1370463282093000)
-------------------
RowKey: 2
=> (cell=2013-06-05 15:11:00-0500, value=3.2, timestamp=1370463332361000)
-------------------
RowKey: 3
=> (cell=2013-06-05 15:11:00-0500, value=3.3, timestamp=1370463332365000)
=> (cell=2013-06-05 15:11:10-0500, value=4.3, timestamp=1370463332368000)
您可以看到群集列collected_at
使此表格宽行(Q.1)。
所以我们可以说,如果一个表有一个或多个聚类键,我们可以调用该表宽行。
让我们再举一个例子:
CREATE TABLE example (
key1 text PRIMARY KEY,
map1 map<text,text>,
list1 list<text>,
set1 set<text>
);
插入数据:
key1 | list1 | map1 | set1
------+-------------------+----------------------------------------------+-----------------------
john | ['doug', 'scott'] | {'doug': '555-1579', 'patricia': '555-4326'} | {'patricia', 'scott'}
现在看一下内部结构:
RowKey: john
=> (column=, value=, timestamp=1374683971220000)
=> (column=map1:doug, value='555-1579', timestamp=1374683971220000)
=> (column=map1:patricia, value='555-4326', timestamp=1374683971220000)
=> (column=list1:26017c10f48711e2801fdf9895e5d0f8, value='doug', timestamp=1374683971220000)
=> (column=list1:26017c12f48711e2801fdf9895e5d0f8, value='scott', timestamp=1374683971220000)
=> (column=set1:'patricia', value=, timestamp=1374683971220000)
=> (column=set1:'scott', value=, timestamp=1374683971220000)
您可以看到存储为动态列的地图键和设置值以及存储为该列值的地图值和列表值。它类似于宽行(Q.2)
最后一个:集合类型映射键和集合大小限制为64k。
资料来源:
https://www.datastax.com/dev/blog/does-cql-support-dynamic-columns-wide-rows
https://teddyma.gitbooks.io/learncassandra/content/model/cql_and_data_structure.html
http://docs.datastax.com/en/cql/3.3/cql/cql_reference/refLimits.html