【TDengine 使用环境】
测试环境
【TDengine 版本】
3.4.1.13
【描述业务影响】
- 业务期望:想把各个子表的按照【小时频率】进行统计聚合后写入聚合表中
SELECT
_wstart AS ts,
tbname AS monitor_common_code,
CAST(AVG(current_value) AS DECIMAL(16,4)) AS avg_value,
max(current_value) AS max_value,
min(current_value) AS min_value,
CAST(SUM(current_value) AS DECIMAL(16,4)) AS sum_value,
cols(max(current_value), ts) AS max_time,
cols(min(current_value), ts) AS min_time
FROM ops_monitor.st_monitor_data_realtime
WHERE ts >= ‘2026-01-01’ AND ts < ‘2026-12-01’
PARTITION BY tbname
INTERVAL(1h) SLIDING(1h);
- 流式计算创建命令:
CREATE STREAM opsmonitor.stream_monitor_stat_hour
INTERVAL(1h) SLIDING(1h)
FROM ops_monitor.st_monitor_data_realtime
PARTITION BY tbname, station_id, line_id, device_id, energy_type, energy_cal_config_flag, monitor_type, monitor_type_code
STREAM_OPTIONS(
WATERMARK(1m) | FILL_HISTORY_FIRST(‘2026-01-01 00:00:00’)
)
INTO ops_monitor.st_monitor_stat_hour
OUTPUT_SUBTABLE(concat('hour’, %%1))
TAGS(
tbname BINARY(128), AS %%1,
station_id BIGINT AS %%2,
line_id BIGINT AS %%3,
device_id BIGINT AS %%4,
energy_type INT AS %%5,
energy_cal_config_flag INT AS %%6,
monitor_type INT AS %%7,
monitor_type_code BINARY(32) AS %%8
)
AS SELECT
_twstart AS ts,
CAST(AVG(current_value) AS DECIMAL(16,4)) AS avg_value,
max(current_value) AS max_value,
min(current_value) AS min_value,
CAST(SUM(current_value) AS DECIMAL(16,4)) AS sum_value,
cols(max(current_value), ts) AS max_time,
cols(min(current_value), ts) AS min_time
FROM ops_monitor.st_monitor_data_realtime
WHERE 1=1 AND energy_type = 0 AND ts >= _twstart AND ts < _twend;
- 问题描述: 同一时间窗口下聚合后的各子表 avg/sum/max/min/maxTime/minTime 值相同???
- 是流式计算命令哪里有问题么?