流式计算执行统计 - 无法将数据写到结果表中 ,或者不正确

【TDengine 使用环境】
测试 环境

【TDengine 版本】3.4

【操作系统以及版本】 debain

【部署方式】 单机版

【描述业务影响】

使用 流式计算 统计 ,结果无法写入结果表中,或者不正确

【遇到的问题:问题现象及影响】

使用 流式计算 统计 ,有联合主键时,结果无法写入结果表中,流式计算的查询部分是有结果的。

没联合主键时,统计结果没有正确写入子表

【资源配置】

测试表sql及流式计算sql 【测试表以商家店铺积分统计为例】

说明:

1 如果目标表有联合主键[COMPOSITE KEY],结果无法写入目标表,执行任务后,结果表是空的,

2 去掉 【COMPOSITE KEY】 统计不正确,没有把正确的结果写到目标表,多个子表出现相同数据,没有把正确数据写到相应的子表; 另外,[去掉联合主键,多店铺数据统计写入肯定是有问题的,表数据是按时间覆盖,先不论]


drop TABLE IF EXISTS `statistics`.test_record ;
CREATE TABLE IF NOT EXISTS `statistics`.test_record (
       ts TIMESTAMP,
       id BIGINT COMPOSITE KEY,
       order_num BIGINT,
       points SMALLINT,
       shop_id bigint

) TAGS (
    merchant_id BIGINT,
    area_code int

);

drop TABLE IF EXISTS  statistics_h.test_income_h;
CREATE TABLE IF NOT EXISTS statistics_h.test_income_h
(
    ts            TIMESTAMP,
    shop_id bigint COMPOSITE KEY,
    points INT
) TAGS (
    merchant_id BIGINT,
    area_code int
);

drop stream IF EXISTS statistics.test_str_h_test_per;
CREATE stream statistics.test_str_h_test_per period ( 1m ) 
FROM
  `statistics`.test_record PARTITION BY merchant_id,area_code 
  INTO statistics_h.test_income_h 
  output_subtable ( concat( 'test_income_h_', cast( merchant_id AS BINARY ), '_', cast( area_code AS BINARY ) ) ) 
  ( ts, shop_id COMPOSITE KEY,  points ) 
  tags ( merchant_id BIGINT AS merchant_id, area_code INT AS area_code ) 
  AS SELECT
  timetruncate ( ts, 1h, 1 ) AS ts,shop_id,
  cast( sum( points ) AS INT ) AS points 
FROM
  statistics.test_record PARTITION BY ts,
  merchant_id,
  area_code, shop_id


测试数据

INSERT INTO 
`statistics`.test_record_101_110000 USING `statistics`.test_record TAGS(101, 110000) 
VALUES 
(now - 1d, 1001, 150, 25, 2001) 
(now - 2d, 1002, 200, 30, 2002) 
(now - 3d, 1003, 120, 20, 2003) 
(now - 25h, 1003, 120, 25, 2003)
`statistics`.test_record_102_120000 USING `statistics`.test_record TAGS(102, 120000) 
VALUES 
(now - 1d, 1004, 180, 35, 2004) 
(now - 2d, 1005, 95, 15, 2005) 
(now - 3d, 1006, 220, 40, 2006) 

`statistics`.test_record_103_130000 USING `statistics`.test_record TAGS(103, 130000) 
VALUES 
(now - 1d, 1007, 165, 28, 2007) 
(now - 2d, 1008, 140, 22, 2008) 
(now - 3d, 1009, 190, 32, 2009) 

`statistics`.test_record_104_140000 USING `statistics`.test_record TAGS(104, 140000) 
VALUES 
(now - 1d, 1010, 175, 27, 2010) 
(now - 2d, 1011, 88, 18, 2011) 
(now - 3d, 1012, 105, 24, 2012) 

`statistics`.test_record_105_150000 USING `statistics`.test_record TAGS(105, 150000) 
VALUES 
(now - 1d, 1013, 75, 12, 2013) 
(now - 2d, 1014, 92, 19, 2014) 
(now - 3d, 1015, 65, 10, 2015) 
(now - 1m, 1015, 65, 10, 2015) 
(now - 1h, 1015, 65, 11, 2015) 
(now - 2h, 1015, 65, 140, 2015) 

`statistics`.test_record_106_160000 USING `statistics`.test_record TAGS(106, 160000) 
VALUES 
(now - 1d, 1016, 130, 26, 2016) 
(now - 2d, 1017, 155, 31, 2017) 
(now - 3d, 1018, 145, 23, 2018);


【报错完整截图】(不要大段的粘贴报错代码,论坛直接看报错代码不直观)

这是我使用以上建表、建流、数据写入的语句后,得到的流计算结果。请看一下结果是哪里不正确?

另外 流计算中 PARTITION BY ts, merchant_id, area_code, shop_id, 需要根据 ts 也分组吗?这个是什么业务逻辑呢?

注意仔细看,店铺ID在每个子表是不是变成相同的两个了,统计的积分是不是不对了,源数据有多少个店铺,统计后有多少个店铺。

这个是每小时统计量,按小时维度的统计,时间是截断到小时,

每个商家的数据方一张子表中,现在的是把某一个商家的放所有子表中了,其它商家没得自己的正确数据