我正在尝试http://planetcassandra.org/getting-started-with-time-series-data-modeling/中提到的 cassandra 中的 Timeseries 示例。现在如何验证图 2 中的示例(根据气象站和日期对行进行分区)仅创建了两行并且每行包含两列?
问候,西努。
我正在尝试http://planetcassandra.org/getting-started-with-time-series-data-modeling/中提到的 cassandra 中的 Timeseries 示例。现在如何验证图 2 中的示例(根据气象站和日期对行进行分区)仅创建了两行并且每行包含两列?
问候,西努。
您可以查询每个分区键“行”并查看其中存在多少“列”(请注意,CQL 中的聚集列是具有公共分区键前缀的行,因此该示例实际上是在 CQL 中创建看起来像四行的内容) .
SELECT event_time, temperature FROM temperature_by_day WHERE weatherstation_id='1234ABCD' AND date='2013-04-03';
event_time | temperature
--------------------------+-------------
2013-04-03 07:01:00-0400 | 72F
2013-04-03 07:02:00-0400 | 73F
SELECT event_time, temperature FROM temperature_by_day WHERE weatherstation_id='1234ABCD' AND date='2013-04-04';
event_time | temperature
--------------------------+-------------
2013-04-04 07:01:00-0400 | 73F
2013-04-04 07:02:00-0400 | 74F
或者一次获取所有聚集的列:
SELECT event_time, temperature FROM temperature_by_day WHERE weatherstation_id='1234ABCD' and DATE in ('2013-04-03', '2013-04-04');
event_time | temperature
--------------------------+-------------
2013-04-03 07:01:00-0400 | 72F
2013-04-03 07:02:00-0400 | 73F
2013-04-04 07:01:00-0400 | 73F
2013-04-04 07:02:00-0400 | 74F
或者只看整个表格的内容:
SELECT * from temperature_by_day ;
weatherstation_id | date | event_time | temperature
-------------------+------------+--------------------------+-------------
1234ABCD | 2013-04-04 | 2013-04-04 07:01:00-0400 | 73F
1234ABCD | 2013-04-04 | 2013-04-04 07:02:00-0400 | 74F
1234ABCD | 2013-04-03 | 2013-04-03 07:01:00-0400 | 72F
1234ABCD | 2013-04-03 | 2013-04-03 07:02:00-0400 | 73F
要查看数据如何存储在磁盘上,您可以将键空间刷新到磁盘,然后对数据文件运行 sstable2json 实用程序。这将表明每个分区键只存储一次,并且集群列在分区键内按排序顺序存储。
root@c1:/var/lib/cassandra/data/tkeyspace/temperature_by_day-e1a74970912211e4aa1ea3121441a41b# sstable2json tkeyspace-temperature_by_day-ka-1-Data.db
[
{"key": "1234ABCD:2013-04-04",
"cells": [["2013-04-04 07\\:01-0400:","",1420054084914905],
["2013-04-04 07\\:01-0400:temperature","73F",1420054084914905],
["2013-04-04 07\\:02-0400:","",1420054155058044],
["2013-04-04 07\\:02-0400:temperature","74F",1420054155058044]]},
{"key": "1234ABCD:2013-04-03",
"cells": [["2013-04-03 07\\:01-0400:","",1420054017282283],
["2013-04-03 07\\:01-0400:temperature","72F",1420054017282283],
["2013-04-03 07\\:02-0400:","",1420054049403031],
["2013-04-03 07\\:02-0400:temperature","73F",1420054049403031]]}
]