Skip to content

Commit 7fa97b1

Browse files
authored
fix[state win]: handle end all-null blocks error (#33669)
1 parent 0913e7b commit 7fa97b1

File tree

3 files changed

+103
-4
lines changed

3 files changed

+103
-4
lines changed

source/libs/executor/src/timewindowoperator.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,10 +1112,12 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator,
11121112
}
11131113
}
11141114

1115-
// if the block ends with null state columns,
1116-
// we do not process them here,
1117-
// since we don't know the belonging of these null rows
1118-
if (pRowSup->numOfRows == 0) {
1115+
if (!pInfo->hasKey ||
1116+
(pRowSup->numOfRows == 0 &&
1117+
extendOption != STATE_WIN_EXTEND_OPTION_BACKWARD)) {
1118+
// if no valid state window or we don't know
1119+
// the belonging of these null rows,
1120+
// just return
11191121
return;
11201122
}
11211123
doKeepCurStateWindowEndInfo(pRowSup, tsList, *endIndex, &extendOption, false);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"filetype": "insert",
3+
"cfgdir": "/etc/taos",
4+
"host": "127.0.0.1",
5+
"port": 6030,
6+
"user": "root",
7+
"password": "taosdata",
8+
"thread_count": 4,
9+
"create_table_thread_count": 4,
10+
"result_file": "./insert_res.txt",
11+
"confirm_parameter_prompt": "no",
12+
"num_of_records_per_req": 10000,
13+
"prepared_rand": 10000,
14+
"chinese": "no",
15+
"escape_character": "yes",
16+
"continue_if_fail": "no",
17+
"databases": [
18+
{
19+
"dbinfo": {
20+
"name": "test_end_null",
21+
"drop": "false",
22+
"vgroups": 2,
23+
"precision": "ms",
24+
"keep": 3650
25+
},
26+
"super_tables": [
27+
{
28+
"name": "test_stb",
29+
"child_table_exists": "no",
30+
"childtable_count": 1,
31+
"childtable_prefix": "d",
32+
"auto_create_table": "no",
33+
"batch_create_tbl_num": 5,
34+
"data_source": "rand",
35+
"insert_mode": "taosc",
36+
"non_stop_mode": "no",
37+
"line_protocol": "line",
38+
"insert_rows": 5000,
39+
"childtable_limit": 0,
40+
"childtable_offset": 0,
41+
"interlace_rows": 0,
42+
"insert_interval": 0,
43+
"partial_col_num": 0,
44+
"timestamp_step": 1000,
45+
"start_timestamp": "2025-10-01 00:00:00.000",
46+
"sample_format": "csv",
47+
"sample_file": "./sample.csv",
48+
"use_sample_ts": "no",
49+
"tags_file": "",
50+
"columns": [
51+
{ "type": "INT", "name": "v", "len": 0 }
52+
],
53+
"tags": [
54+
{"type": "TINYINT", "name": "groupid", "max": 10, "min": 1},
55+
{"type": "BINARY", "name": "location", "len": 16,
56+
"values": ["San Francisco", "Los Angles", "San Diego",
57+
"San Jose", "Palo Alto", "Campbell", "Mountain View",
58+
"Sunnyvale", "Santa Clara", "Cupertino"]
59+
}
60+
]
61+
}
62+
]
63+
}
64+
]
65+
}
66+

test/cases/13-TimeSeriesExt/04-StateWindow/test_state_window_null_block.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# -*- coding: utf-8 -*-
1313

14+
import os
1415
from new_test_framework.utils import tdSql, tdLog, tdCom, tdStream
1516
from new_test_framework.utils import etool
1617

@@ -45,6 +46,7 @@ def test_state_window_null_block(self):
4546
4647
"""
4748
self.prepare_data()
49+
self.check_end_with_null_block()
4850
self.check_all_non_null()
4951
self.check_inner_null()
5052
self.check_border_null1()
@@ -77,6 +79,14 @@ def prepare_data(self):
7779
datafile = etool.getFilePath(__file__, "data", "data6.csv")
7880
tdSql.execute(f"insert into t6 file '{datafile}'")
7981

82+
# prepare with taosBenchmark
83+
# insert 5k rows with all nulls
84+
json_file = os.path.join(os.path.dirname(__file__), "json/all_null_5k.json")
85+
etool.benchMark(json=json_file)
86+
# insert to create a window
87+
tdSql.execute("use test_end_null")
88+
tdSql.execute("insert into d0 values('2025-10-01 01:00:00', 1);")
89+
8090
# test data pattern:
8191
# | true ... true | true ... false | true ... true |
8292
def check_all_non_null(self):
@@ -544,3 +554,24 @@ def check_all_null_block2(self):
544554
tdSql.checkData(2, 2, True)
545555
tdSql.checkData(2, 3, 5995)
546556
tdSql.checkData(2, 4, 3995)
557+
558+
def check_end_with_null_block(self):
559+
tdSql.execute("use test_end_null")
560+
tdSql.query("select _wstart, _wend, count(*), sum(v) from d0 state_window(v)", show=True)
561+
tdSql.checkRows(1)
562+
tdSql.checkData(0, 0, "2025-10-01 01:00:00.000")
563+
tdSql.checkData(0, 1, "2025-10-01 01:00:00.000")
564+
tdSql.checkData(0, 2, 1)
565+
tdSql.checkData(0, 3, 1)
566+
tdSql.query("select _wstart, _wend, count(*), sum(v) from d0 state_window(v, 1)", show=True)
567+
tdSql.checkRows(1)
568+
tdSql.checkData(0, 0, "2025-10-01 01:00:00.000")
569+
tdSql.checkData(0, 1, "2025-10-01 01:23:19.000")
570+
tdSql.checkData(0, 2, 1400)
571+
tdSql.checkData(0, 3, 1)
572+
tdSql.query("select _wstart, _wend, count(*), sum(v) from d0 state_window(v, 2)", show=True)
573+
tdSql.checkRows(1)
574+
tdSql.checkData(0, 0, "2025-10-01 00:00:00.000")
575+
tdSql.checkData(0, 1, "2025-10-01 01:00:00.000")
576+
tdSql.checkData(0, 2, 3601)
577+
tdSql.checkData(0, 3, 1)

0 commit comments

Comments
 (0)