taosdata / TDengine

High-performance, scalable time-series database designed for Industrial IoT (IIoT) scenarios
https://tdengine.com
GNU Affero General Public License v3.0
23.2k stars 4.84k forks source link

help with single site windowed query with join #25656

Open liujiangithub opened 4 months ago

liujiangithub commented 4 months ago

数据现状: 1 超级表字段 (ts timestamp, v double), tag(设备,变量名) 2 存储单点数据,每个设备的每个变量单独一张子表。每个设备的变量上报周期不完全相同(ts不一致)。 需求: 需要查询某个时间段,某个周期,某些设备某些变量的值,如每分钟,2个设备4个变量的值,返回结果格式如下 时间 设备 变量1 变量2 变量3 变量4 2024-05-07 11:37:00.0000000 device1 1.1 xx yy zz 2024-05-07 11:37:00.0000000 device2 2.1 ...
2024-05-07 11:38:00.0000000 device1 1.2 ...
2024-05-07 11:38:00.0000000 device2 2.2 ...

现有尝试: 子查询使用子表窗口查询得到子表每分钟的值,再嵌套时间相等的联表查询,如 select * from (select tbname as tn,_wstart as t,first(value) as v from table2 where ts >='2024-05-06 07:00:00.000' and ts <= '2024-05-06 11:05:00' partition by tbname interval(10m) fill(prev)) t1,(select tbname as tn,_wstart as t,first(value) as v from table3 where ts >='2024-05-06 07:00:00.000' and ts <= '2024-05-06 11:05:00' partition by tbname interval(10m) fill(prev)) t2 where t1.t = t2.t; 收到失败:DB error: Join requires valid time series input 看起来是连接条件时间不对。

操作截图: 企业微信截图_17151320905648

问题: 1 联表查询必须是真实的表的时间字段么,子查询中的时间字段作为join条件不行? 2 如果使用stream将原始表每分钟的数据导入到另外一张超级表,然后从新表中使用时间戳联表查询这种方式是否可行? 3 目前不想创建stream, 产生多余一份数据存储的情况下,对这类需求有什么更好的方式? 4 这类单点数据最终聚合成一张表的需求应该不是个例,官方对这类问题的处理建议是什么?

NephilimJaeger commented 1 month ago

Im having the same issue. Any tips?