【TDengine 使用环境】
测试
【TDengine 版本】
3.3.8.8
【操作系统以及版本】
【部署方式】容器/非容器部署
非容器部署
【集群节点数】
1
【集群副本数】
1
【描述业务影响】
TDengin 流计算如何更精确时间,目前想做到的效果是 在到达分、时、天获取到最近的数据,
例如 9:01 应该写入 9:00 -9:01 的数据 9:00 写入 8:00 -9:00 的数据
但是目前这个流Sql 的结果时提前一分钟 一小时 一天,设置 watermark = 0 也没有获取到想要的结果
分:
create stream if not exists stream_dwd_agg_m interval(1m) sliding (1m) from zhsc_dev.dwd_measure_point partition by device_id, point_id stream_options ( watermark (1m) | fill_history (1) ) into zhsc_dev.dwd_agg_m tags ( device_id nchar (64) as device_id, point_id nchar (128) as point_id ) as select _twstart as ts, _twend as wend, first (v) as first_v, last (v) as last_v, last (v) - first (v) as diff_v, avg(v) as avg_v, sum(v) as sum_v, max(v) as max_v, min(v) as min_v, count(*) as row_count from zhsc_dev.dwd_measure_point where device_id = %%1 and point_id = %%2 and _c0 >= _twstart and _c0 < _twend;
时:
create stream if not exists stream_dwd_agg_h interval(1h) sliding (1h) from zhsc_dev.dwd_measure_point partition by device_id, point_id stream_options ( watermark (1h) | fill_history (1) ) into zhsc_dev.dwd_agg_h tags ( device_id nchar (64) as device_id, point_id nchar (128) as point_id ) as select _twstart as ts, _twend as wend, first (first_v) as first_v, last (last_v) as last_v, last (last_v) - first (first_v) as diff_v, avg (avg_v) as avg_v, sum (sum_v) as sum_v, max (max_v) as max_v, min (min_v) as min_v, count (row_count) as row_count from zhsc_dev.dwd_agg_m where device_id = %%1 and point_id = %%2 and _c0 >= _twstart and _c0 < _twend;
天:
create stream if not exists stream_dwd_agg_d interval(1d) sliding (1d) from zhsc_dev.dwd_measure_point partition by device_id, point_id stream_options ( watermark (1d) | fill_history (1) ) into zhsc_dev.dwd_agg_d tags ( device_id nchar (64) as device_id, point_id nchar (128) as point_id ) as select _twstart as ts, _twend as wend, first (first_v) as first_v, last (last_v) as last_v, last (last_v) - first (first_v) as diff_v, avg (avg_v) as avg_v, sum (sum_v) as sum_v, max (max_v) as max_v, min (min_v) as min_v, count (row_count) as row_count from zhsc_dev.dwd_agg_h where device_id = %%1 and point_id = %%2 and _c0 >= _twstart and _c0 < _twend;
