卡桑德拉时间序列查询

时间:2016-11-29 19:26:16

标签: cassandra time-series cqlsh

您好我想查询定期发送警报的某些设备的数据。所以我想要一个时间序列。 我创建了一个这样的表:

CREATE TABLE alerts_by_day (
    day_of_year int,
    year int,
    alert_timestamp timestamp,
    serial_number text,
    alert_id uuid,
    alert_type text,
  PRIMARY KEY((day_of_year, year), serial_number, alert_timestamp, alert_type,alert_id)
) WITH CLUSTERING ORDER BY (serial_number DESC, alert_timestamp DESC, alert_type DESC);

现在我想创建一个查询或物化视图,以便能够按时间范围(即:从2015年11月29日到2016年1月20日)和警报类型进行查询。所以我只想显示特定类型和时间范围的警报。我可以查询某个时间范围:

Select * from alerts_by_day
where day_of_year IN (312,313)
and year IN (2016,2015) 
and alert_timestamp < '2016-11-08 03:09:14-0800'
and alert_timestamp > '2016-11-07 23:13:28-0800'

但我不能这样做:

Select * from alerts_by_day
where day_of_year IN (312,313)
and year IN (2016,2015) 
and alert_timestamp < '2016-11-08 03:09:14-0800'
and alert_timestamp > '2016-11-07 23:13:28-0800'
and alert_type IN ('type1', 'type2')

因为我使用了对于alert_timestamp不是EQ的限制。

我怎么能实现这一点我只能看到类型1和类型2的警报?

这是错误: 无法执行CQL脚本:无法限制群集列alert_type(precingign列alert_timestamp受非EQ关系限制)

1 个答案:

答案 0 :(得分:0)

您将能够使用Spark

过滤和汇总时间序列
相关问题