【发布时间】:2018-07-28 17:04:04
【问题描述】:
我需要以下用例的最佳方法,
我有“设备”表(只有一个分区 ID:“设备”),还有另一个表“设备统计”(分区 ID:“设备 ID”,因此该表的分区数与设备数一样多),这意味着对于每台设备,每分钟都会收集一次统计信息。
CREATE TABLE device(
"partitionId" text,"name" text,"deviceId" text, ..., primary key ("partitionId","name","deviceId"));
其中 partitionId - 它是一个常量(“设备”)
CREATE TABLE deviceStatistics (
"deviceId" text,
"timestamp" timestamp, ...,
primary key ("deviceId","timestamp")) with clustering order by ("timestamp" DESC);
其中 'deviceId' - 它是分区键,每个分区下都有时间戳条目列表
到此为止没问题,因为我只需要以下查询,
1) select * from device where partitionId = 'device'
- which list all the devices available.
2) select * from deviceStatistics where deviceId = 'deviceId_1'
- which list all the device statistics for a deviceId
3) select * from deviceStatistics where deviceId = 'deviceId_1' LIMIT 1
- which gets the most recent statistics for a deviceId
现在我需要以下用例的解决方案,
我需要收集集群级别的统计信息,这意味着我需要收集时间戳的所有设备统计信息,
(即)如果 4 个设备的 deviceStatistics 可用于时间戳,那么我需要收集时间戳的所有四个统计信息并添加到设备组级别。
这意味着我的 DeviceGroupstatistics 是时间戳的所有设备统计信息的聚合。
现在的问题是,由于我将“deviceId”作为 deviceStatistics 表的 partitionId,因此我需要对所有 deviceId 执行此查询(从 deviceStatistics 中选择 *,其中 deviceId = 'deviceId' LIMIT 1)。 所以假设我有 1000 台设备,那么我需要每分钟为所有 1000 台设备触发此查询。
有没有更好的设计呢?
【问题讨论】: