我关注的是Patrick McFadin在PlanetCassandra中的TimeSeries数据建模。关于这一点,我有一个问题:
如果我还需要存储气象站名称,它是否应该在同一个表中,例如:
创建表测试(wea_id int,wea_name text,wea_add text,eventday timeuuid,eventtime timeuuid,temp int,PRIMARY KEY ((wea_id,wea_id),eventtime) );
这迫使我为每个新行输入wea_name和wea_add,那么如何识别已经创建的新行呢?或者,是否有更好的机制来对上述数据进行建模?
你好,Seenu。
发布于 2015-02-03 11:48:18
我假设您指的是关于http://planetcassandra.org/getting-started-with-time-series-data-modeling/时间序列数据建模入门的文章
列出的原始CQL为:
CREATE TABLE temperature_by_day (
weatherstation_id text,
date text,
event_time timestamp,
temperature text,
PRIMARY KEY ((weatherstation_id,date),event_time)
);如果需要添加与分区键相关联的属性,在本例中为(weatherstation_id,date),Cassandra有一个特性可以完成此任务: static columns http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/refStaticCol.html
因此,您可以将语句编写为:
CREATE TABLE temperature_by_day (
weatherstation_id text,
weatherstation_name text STATIC,
date text,
event_time timestamp,
temperature text,
PRIMARY KEY ((weatherstation_id,date),event_time)
);您将为每个(weatherstation_id,date)组合存储一次名称,而不是为每个观察值存储一次名称。
理想情况下,您希望为每个气象站存储一次名称。使用此分区键选择,您无法做到这一点;如果您愿意,您可以按照Patrick的第一个示例为每个分区建模一个设备:
CREATE TABLE temperature (
weatherstation_id text,
weatherstation_name text STATIC,
event_time timestamp,
temperature text,
PRIMARY KEY ((weatherstation_id),event_time)
);https://stackoverflow.com/questions/28106014
复制相似问题