表中的行/列数

时间:2014-12-30 18:24:56

标签: cassandra cassandra-cli

我正在试验http://planetcassandra.org/getting-started-with-time-series-data-modeling/中提到的cassandra中的Timeseries示例。    现在,我如何验证图2中的示例(根据气象站和日期对行进行分区)仅创建了两行,每行包含两列?

此致 色努。

1 个答案:

答案 0 :(得分:1)

您可以查询每个分区键" row"看看有多少"列"存在于其中(请注意,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]]}
]