mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
1673 lines
88 KiB
Python
1673 lines
88 KiB
Python
import time
|
|
from new_test_framework.utils import (tdLog,tdSql,tdStream,StreamCheckItem,)
|
|
|
|
|
|
class TestStreamOptionsTrigger:
|
|
|
|
def setup_class(cls):
|
|
tdLog.debug(f"start to execute {__file__}")
|
|
|
|
def test_stream_options_trigger(self):
|
|
"""Stream basic test 1
|
|
"""
|
|
|
|
tdStream.createSnode()
|
|
|
|
streams = []
|
|
# streams.append(self.Basic0())
|
|
streams.append(self.Basic1()) # expired_time
|
|
# streams.append(self.Basic2())
|
|
# streams.append(self.Basic3())
|
|
# streams.append(self.Basic4())
|
|
# streams.append(self.Basic5())
|
|
# streams.append(self.Basic6())
|
|
# streams.append(self.Basic7())
|
|
# streams.append(self.Basic8())
|
|
|
|
tdStream.checkAll(streams)
|
|
|
|
class Basic0(StreamCheckItem):
|
|
def __init__(self):
|
|
self.db = "sdb0"
|
|
self.stbName = "stb"
|
|
|
|
def create(self):
|
|
tdSql.execute(f"create database {self.db} vgroups 1 buffer 8")
|
|
tdSql.execute(f"use {self.db}")
|
|
tdSql.execute(f"create table if not exists {self.stbName} (cts timestamp, cint int) tags (tint int)")
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(1)
|
|
|
|
tdSql.execute(f"create table ct1 using stb tags(1)")
|
|
tdSql.execute(f"create table ct2 using stb tags(2)")
|
|
tdSql.execute(f"create table ct3 using stb tags(3)")
|
|
tdSql.execute(f"create table ct4 using stb tags(4)")
|
|
|
|
tdSql.query(f"show tables")
|
|
tdSql.checkRows(4)
|
|
|
|
tdSql.execute(
|
|
f"create stream s0 state_window(cint) from ct1 into res_ct1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
tdSql.execute(
|
|
f"create stream s0_g state_window(cint) from {self.stbName} partition by tbname, tint into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
def insert1(self):
|
|
sqls = [
|
|
"insert into ct1 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct2 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct3 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct3 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct3 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct4 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct4 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct4 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:09', 3);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check1(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_ct%"',
|
|
func=lambda: tdSql.getRows() == 1,
|
|
)
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"',
|
|
func=lambda: tdSql.getRows() == 4,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_ct1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:01")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:02")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:4")
|
|
and tdSql.compareData(1, 2, 3)
|
|
and tdSql.compareData(1, 3, 3)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(2, 2, 4)
|
|
and tdSql.compareData(2, 3, 8)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:01")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:02")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:4")
|
|
and tdSql.compareData(1, 2, 3)
|
|
and tdSql.compareData(1, 3, 3)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(2, 2, 4)
|
|
and tdSql.compareData(2, 3, 8)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
class Basic1(StreamCheckItem):
|
|
def __init__(self):
|
|
self.db = "sdb1"
|
|
self.stbName = "stb"
|
|
self.vstbName = "vstb"
|
|
|
|
def create(self):
|
|
tdSql.execute(f"create database {self.db} vgroups 1 buffer 8")
|
|
tdSql.execute(f"use {self.db}")
|
|
tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int) tags (tint int)")
|
|
tdSql.execute(f"create table if not exists {self.db}.{self.vstbName} (cts timestamp, cint int) tags (tint int) virtual 1")
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(2)
|
|
|
|
tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} tags(1)")
|
|
# tdSql.execute(f"create table {self.db}.ct2 using {self.db}.{self.stbName} tags(1)")
|
|
# tdSql.execute(f"create table {self.db}.ct3 using {self.db}.{self.stbName} tags(1)")
|
|
# tdSql.execute(f"create table {self.db}.ct4 using {self.db}.{self.stbName} tags(1)")
|
|
|
|
tdSql.execute(f"create vtable {self.db}.vct1 (cint from ct1.cint) using {self.db}.{self.vstbName} tags(101)")
|
|
tdSql.execute(f"create vtable {self.db}.vct2 (cint from ct1.cint) using {self.db}.{self.vstbName} tags(101)")
|
|
tdSql.execute(f"create vtable {self.db}.vct3 (cint from ct1.cint) using {self.db}.{self.vstbName} tags(101)")
|
|
tdSql.execute(f"create vtable {self.db}.vct4 (cint from ct1.cint) using {self.db}.{self.vstbName} tags(101)")
|
|
|
|
tdSql.query(f"show tables")
|
|
tdSql.checkRows(1)
|
|
tdSql.query(f"show vtables")
|
|
tdSql.checkRows(4)
|
|
|
|
tdSql.execute(
|
|
f"create stream s1 state_window(cint) from vct1 into res_vct1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
# tdSql.execute(
|
|
# f"create stream s1_g state_window(cint) from {self.vstbName} partition by tbname, tint options(expired_time(10s)) into res_vstb OUTPUT_SUBTABLE(CONCAT('res_vstb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
# )
|
|
|
|
def insert1(self):
|
|
sqls = [
|
|
"insert into ct1 values ('2025-01-01 00:00:00', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:05', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:10', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:15', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:20', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:25', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:30', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:35', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:40', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:45', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:50', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:55', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:01:00', 3);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check1(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_vtables where db_name="{self.db}" and table_name="res_vct1"',
|
|
func=lambda: tdSql.getRows() == 1,
|
|
)
|
|
# tdSql.checkResultsByFunc(
|
|
# sql=f'select * from information_schema.ins_vtables where db_name="{self.db}" and table_name like "res_vstb_ct%"',
|
|
# func=lambda: tdSql.getRows() == 4,
|
|
# )
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_vct1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_vct1",
|
|
func=lambda: tdSql.getRows() == 2
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:25")
|
|
and tdSql.compareData(0, 2, 6)
|
|
and tdSql.compareData(0, 3, 6)
|
|
and tdSql.compareData(0, 4, 1)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:30")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:55")
|
|
and tdSql.compareData(1, 2, 6)
|
|
and tdSql.compareData(1, 3, 12)
|
|
and tdSql.compareData(1, 4, 2),
|
|
)
|
|
|
|
# tdSql.checkResultsByFunc(
|
|
# sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_vstb_ct4",
|
|
# func=lambda: tdSql.getRows() == 2
|
|
# and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
# and tdSql.compareData(0, 1, "2025-01-01 00:00:25")
|
|
# and tdSql.compareData(0, 2, 6)
|
|
# and tdSql.compareData(0, 3, 6)
|
|
# and tdSql.compareData(0, 4, 1)
|
|
# and tdSql.compareData(1, 0, "2025-01-01 00:00:30")
|
|
# and tdSql.compareData(1, 1, "2025-01-01 00:00:55")
|
|
# and tdSql.compareData(1, 2, 6)
|
|
# and tdSql.compareData(1, 3, 12)
|
|
# and tdSql.compareData(1, 4, 2),
|
|
# )
|
|
|
|
def insert2(self):
|
|
sqls = [
|
|
# "insert into ct1 values ('2025-01-01 00:00:00', 1);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:05', 1);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:10', 1);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:15', 1);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:20', 1);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:25', 1);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:30', 2);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:35', 2);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:40', 2);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:45', 2);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:50', 2);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:55', 2);",
|
|
|
|
"insert into ct1 values ('2025-01-01 00:00:26', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:51', 2);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check2(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_vct1",
|
|
func=lambda: tdSql.getRows() == 2
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:25")
|
|
and tdSql.compareData(0, 2, 6)
|
|
and tdSql.compareData(0, 3, 6)
|
|
and tdSql.compareData(0, 4, 1)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:30")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:55")
|
|
and tdSql.compareData(1, 2, 7)
|
|
and tdSql.compareData(1, 3, 14)
|
|
and tdSql.compareData(1, 4, 2),
|
|
)
|
|
|
|
# tdSql.checkResultsByFunc(
|
|
# sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_vstb_ct4",
|
|
# func=lambda: tdSql.getRows() == 2
|
|
# and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
# and tdSql.compareData(0, 1, "2025-01-01 00:00:25")
|
|
# and tdSql.compareData(0, 2, 6)
|
|
# and tdSql.compareData(0, 3, 6)
|
|
# and tdSql.compareData(0, 4, 1)
|
|
# and tdSql.compareData(1, 0, "2025-01-01 00:00:30")
|
|
# and tdSql.compareData(1, 1, "2025-01-01 00:00:55")
|
|
# and tdSql.compareData(1, 2, 7)
|
|
# and tdSql.compareData(1, 3, 14)
|
|
# and tdSql.compareData(1, 4, 2),
|
|
# )
|
|
|
|
class Basic2(StreamCheckItem):
|
|
def __init__(self):
|
|
self.db = "sdb2"
|
|
self.stbName = "stb"
|
|
self.vstbName = "vstb"
|
|
|
|
def create(self):
|
|
tdSql.execute(f"create database {self.db} vgroups 1 buffer 8")
|
|
tdSql.execute(f"use {self.db}")
|
|
tdSql.execute(f"create table if not exists {self.db}.{self.stbName} (cts timestamp, cint int) tags (tint int)")
|
|
tdSql.execute(f"create table if not exists {self.db}.{self.vstbName} (cts timestamp, cint int) tags (tint int) virtual 1")
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(2)
|
|
|
|
tdSql.execute(f"create table {self.db}.ct1 using {self.db}.{self.stbName} tags(1)")
|
|
|
|
tdSql.execute(f"create vtable {self.db}.vct1 (cint from ct1.cint) using {self.db}.{self.vstbName} tags(101)")
|
|
# tdSql.execute(f"create vtable {self.db}.vct2 (cint from ct1.cint) using {self.db}.{self.vstbName} tags(101)")
|
|
# tdSql.execute(f"create vtable {self.db}.vct3 (cint from ct1.cint) using {self.db}.{self.vstbName} tags(101)")
|
|
# tdSql.execute(f"create vtable {self.db}.vct4 (cint from ct1.cint) using {self.db}.{self.vstbName} tags(101)")
|
|
|
|
tdSql.query(f"show tables")
|
|
tdSql.checkRows(1)
|
|
tdSql.query(f"show vtables")
|
|
tdSql.checkRows(1)
|
|
|
|
# tdSql.execute(
|
|
# f"create stream s1 state_window(cint) from vct1 options(expired_time(10s)) into res_vct1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from vct1;"
|
|
# )
|
|
tdSql.execute(
|
|
f"create stream s1_g state_window(cint) from {self.vstbName} partition by tbname, tint options(expired_time(10s)) into res_vstb OUTPUT_SUBTABLE(CONCAT('res_vstb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%tbname;"
|
|
)
|
|
|
|
def insert1(self):
|
|
sqls = [
|
|
"insert into ct1 values ('2025-01-01 00:00:00', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:05', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:10', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:15', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:20', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:25', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:30', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:35', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:40', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:45', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:50', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:55', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:01:00', 3);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check1(self):
|
|
# tdSql.checkResultsByFunc(
|
|
# sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name="res_vct1"',
|
|
# func=lambda: tdSql.getRows() == 1,
|
|
# )
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_vstb_vct%"',
|
|
func=lambda: tdSql.getRows() == 1,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_vstb_vct1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
# tdSql.checkResultsByFunc(
|
|
# sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_vct1",
|
|
# # func=lambda: tdSql.getRows() == 2
|
|
# # and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
# # and tdSql.compareData(0, 1, "2025-01-01 00:00:25")
|
|
# # and tdSql.compareData(0, 2, 6)
|
|
# # and tdSql.compareData(0, 3, 6)
|
|
# # and tdSql.compareData(0, 4, 1)
|
|
# # and tdSql.compareData(1, 0, "2025-01-01 00:00:30")
|
|
# # and tdSql.compareData(1, 1, "2025-01-01 00:00:55")
|
|
# # and tdSql.compareData(1, 2, 6)
|
|
# # and tdSql.compareData(1, 3, 12)
|
|
# # and tdSql.compareData(1, 4, 2),
|
|
# func=lambda: tdSql.getRows() == 1
|
|
# and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
# and tdSql.compareData(0, 1, "2025-01-01 00:00:25")
|
|
# and tdSql.compareData(0, 2, 13)
|
|
# and tdSql.compareData(0, 3, 21)
|
|
# # and tdSql.compareData(0, 4, 1.615),
|
|
# )
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_vstb_vct1",
|
|
func=lambda: tdSql.getRows() == 2
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:25")
|
|
and tdSql.compareData(0, 2, 6)
|
|
and tdSql.compareData(0, 3, 6)
|
|
and tdSql.compareData(0, 4, 1)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:30")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:55")
|
|
and tdSql.compareData(1, 2, 6)
|
|
and tdSql.compareData(1, 3, 12)
|
|
and tdSql.compareData(1, 4, 2),
|
|
)
|
|
|
|
# def insert2(self):
|
|
# sqls = [
|
|
# # "insert into ct1 values ('2025-01-01 00:00:00', 1);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:05', 1);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:10', 1);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:15', 1);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:20', 1);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:25', 1);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:30', 2);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:35', 2);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:40', 2);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:45', 2);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:50', 2);",
|
|
# # "insert into ct1 values ('2025-01-01 00:00:55', 2);",
|
|
|
|
# "insert into ct1 values ('2025-01-01 00:00:26', 1);",
|
|
# "insert into ct1 values ('2025-01-01 00:00:51', 2);",
|
|
# ]
|
|
# tdSql.executes(sqls)
|
|
|
|
# def check2(self):
|
|
# tdSql.checkResultsByFunc(
|
|
# sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_vct1",
|
|
# func=lambda: tdSql.getRows() == 2
|
|
# and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
# and tdSql.compareData(0, 1, "2025-01-01 00:00:25")
|
|
# and tdSql.compareData(0, 2, 6)
|
|
# and tdSql.compareData(0, 3, 6)
|
|
# and tdSql.compareData(0, 4, 1)
|
|
# and tdSql.compareData(1, 0, "2025-01-01 00:00:30")
|
|
# and tdSql.compareData(1, 1, "2025-01-01 00:00:55")
|
|
# and tdSql.compareData(1, 2, 7)
|
|
# and tdSql.compareData(1, 3, 14)
|
|
# and tdSql.compareData(1, 4, 2),
|
|
# )
|
|
|
|
# # tdSql.checkResultsByFunc(
|
|
# # sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_vstb_ct4",
|
|
# # func=lambda: tdSql.getRows() == 2
|
|
# # and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
# # and tdSql.compareData(0, 1, "2025-01-01 00:00:25")
|
|
# # and tdSql.compareData(0, 2, 6)
|
|
# # and tdSql.compareData(0, 3, 6)
|
|
# # and tdSql.compareData(0, 4, 1)
|
|
# # and tdSql.compareData(1, 0, "2025-01-01 00:00:30")
|
|
# # and tdSql.compareData(1, 1, "2025-01-01 00:00:55")
|
|
# # and tdSql.compareData(1, 2, 7)
|
|
# # and tdSql.compareData(1, 3, 14)
|
|
# # and tdSql.compareData(1, 4, 2),
|
|
# # )
|
|
|
|
class Basic3(StreamCheckItem):
|
|
def __init__(self):
|
|
self.db = "sdb3"
|
|
self.stbName = "stb"
|
|
|
|
def create(self):
|
|
tdSql.execute(f"create database {self.db} vgroups 1 buffer 8")
|
|
tdSql.execute(f"use {self.db}")
|
|
tdSql.execute(f"create table if not exists {self.stbName} (cts timestamp, cint int) tags (tint int)")
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(1)
|
|
|
|
tdSql.execute(f"create table ct1 using stb tags(1)")
|
|
tdSql.execute(f"create table ct2 using stb tags(2)")
|
|
|
|
|
|
tdSql.execute(f"create table ct3 using stb tags(3)")
|
|
tdSql.execute(f"create table ct4 using stb tags(3)")
|
|
tdSql.execute(f"create table ct5 using stb tags(3)")
|
|
|
|
tdSql.query(f"show tables")
|
|
tdSql.checkRows(5)
|
|
|
|
tdSql.execute(
|
|
f"create stream s3 state_window(cint) from ct1 options(force_output) into res_ct1 (startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s) as select _twstart, first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint), _twrownum from ct2 where _c0 >= _twstart and _c0 <= _twend;"
|
|
)
|
|
tdSql.execute(
|
|
f"create stream s3_g state_window(cint) from {self.stbName} partition by tbname, tint options(force_output | pre_filter(tint=3)) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v, rownum_s) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint), _twrownum from ct2 where _c0 >= _twstart and _c0 <= _twend;"
|
|
)
|
|
|
|
def insert1(self):
|
|
sqls = [
|
|
"insert into ct2 values ('2025-01-01 00:00:10', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:11', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:12', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:16', 3);",
|
|
"insert into ct2 values ('2025-01-01 00:00:17', 3);",
|
|
"insert into ct2 values ('2025-01-01 00:00:18', 3);",
|
|
"insert into ct2 values ('2025-01-01 00:00:19', 4);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
sqls = [
|
|
"insert into ct1 values ('2025-01-01 00:00:10', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:11', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:12', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:13', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:14', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:15', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:16', 3);",
|
|
"insert into ct1 values ('2025-01-01 00:00:17', 3);",
|
|
"insert into ct1 values ('2025-01-01 00:00:18', 3);",
|
|
"insert into ct1 values ('2025-01-01 00:00:19', 4);",
|
|
|
|
"insert into ct3 values ('2025-01-01 00:00:10', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:11', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:12', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:13', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:14', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:15', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:16', 3);",
|
|
"insert into ct3 values ('2025-01-01 00:00:17', 3);",
|
|
"insert into ct3 values ('2025-01-01 00:00:18', 3);",
|
|
"insert into ct3 values ('2025-01-01 00:00:19', 4);",
|
|
|
|
"insert into ct4 values ('2025-01-01 00:00:10', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:11', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:12', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:13', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:14', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:15', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:16', 3);",
|
|
"insert into ct4 values ('2025-01-01 00:00:17', 3);",
|
|
"insert into ct4 values ('2025-01-01 00:00:18', 3);",
|
|
"insert into ct4 values ('2025-01-01 00:00:19', 4);",
|
|
|
|
"insert into ct5 values ('2025-01-01 00:00:10', 1);",
|
|
"insert into ct5 values ('2025-01-01 00:00:11', 1);",
|
|
"insert into ct5 values ('2025-01-01 00:00:12', 1);",
|
|
"insert into ct5 values ('2025-01-01 00:00:13', 2);",
|
|
"insert into ct5 values ('2025-01-01 00:00:14', 2);",
|
|
"insert into ct5 values ('2025-01-01 00:00:15', 2);",
|
|
"insert into ct5 values ('2025-01-01 00:00:16', 3);",
|
|
"insert into ct5 values ('2025-01-01 00:00:17', 3);",
|
|
"insert into ct5 values ('2025-01-01 00:00:18', 3);",
|
|
"insert into ct5 values ('2025-01-01 00:00:19', 4);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check1(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name="res_ct1"',
|
|
func=lambda: tdSql.getRows() == 1,
|
|
)
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"',
|
|
func=lambda: tdSql.getRows() == 3,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_ct1",
|
|
schema=[
|
|
["startts", "TIMESTAMP", 8, ""],
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
["rownum_s", "BIGINT", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_ct1",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(0, 2, "2025-01-01 00:00:12")
|
|
and tdSql.compareData(0, 3, 3)
|
|
and tdSql.compareData(0, 4, 3)
|
|
and tdSql.compareData(0, 5, 1)
|
|
and tdSql.compareData(0, 6, 3)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:13")
|
|
and tdSql.compareData(1, 1, None)
|
|
and tdSql.compareData(1, 2, None)
|
|
and tdSql.compareData(1, 3, None)
|
|
and tdSql.compareData(1, 4, None)
|
|
and tdSql.compareData(1, 5, None)
|
|
and tdSql.compareData(1, 6, 3)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:16")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:16")
|
|
and tdSql.compareData(2, 2, "2025-01-01 00:00:18")
|
|
and tdSql.compareData(2, 3, 3)
|
|
and tdSql.compareData(2, 4, 9)
|
|
and tdSql.compareData(2, 5, 3)
|
|
and tdSql.compareData(2, 6, 3),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select startts, firstts, lastts, cnt_v, sum_v, avg_v, rownum_s from {self.db}.res_stb_ct5",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(0, 2, "2025-01-01 00:00:12")
|
|
and tdSql.compareData(0, 3, 3)
|
|
and tdSql.compareData(0, 4, 3)
|
|
and tdSql.compareData(0, 5, 1)
|
|
and tdSql.compareData(0, 6, 3)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:13")
|
|
and tdSql.compareData(1, 1, None)
|
|
and tdSql.compareData(1, 2, None)
|
|
and tdSql.compareData(1, 3, None)
|
|
and tdSql.compareData(1, 4, None)
|
|
and tdSql.compareData(1, 5, None)
|
|
and tdSql.compareData(1, 6, 3)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:16")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:16")
|
|
and tdSql.compareData(2, 2, "2025-01-01 00:00:18")
|
|
and tdSql.compareData(2, 3, 3)
|
|
and tdSql.compareData(2, 4, 9)
|
|
and tdSql.compareData(2, 5, 3)
|
|
and tdSql.compareData(2, 6, 3),
|
|
)
|
|
|
|
class Basic4(StreamCheckItem):
|
|
def __init__(self):
|
|
self.db = "sdb4"
|
|
self.stbName = "stb"
|
|
|
|
def create(self):
|
|
tdSql.execute(f"create database {self.db} vgroups 1 buffer 8")
|
|
tdSql.execute(f"use {self.db}")
|
|
tdSql.execute(f"create table if not exists {self.stbName} (cts timestamp, cint int) tags (tint int)")
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(1)
|
|
|
|
tdSql.execute(f"create table ct1 using stb tags(1)")
|
|
tdSql.execute(f"create table ct2 using stb tags(2)")
|
|
tdSql.execute(f"create table ct3 using stb tags(2)")
|
|
tdSql.execute(f"create table ct4 using stb tags(2)")
|
|
|
|
tdSql.query(f"show tables")
|
|
tdSql.checkRows(4)
|
|
|
|
tdSql.execute(
|
|
f"create stream s4 state_window(cint) from ct1 options(pre_filter(cint < 5)) into res_ct1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
tdSql.execute(
|
|
f"create stream s4_g state_window(cint) from {self.stbName} partition by tbname, tint options(pre_filter(cint < 5 and tint=2)) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
def insert1(self):
|
|
sqls = [
|
|
"insert into ct1 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:02', 6);",
|
|
"insert into ct1 values ('2025-01-01 00:00:03', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:05', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:06', 7);",
|
|
"insert into ct1 values ('2025-01-01 00:00:07', 7);",
|
|
"insert into ct1 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct2 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:02', 6);",
|
|
"insert into ct2 values ('2025-01-01 00:00:03', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:05', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:06', 7);",
|
|
"insert into ct2 values ('2025-01-01 00:00:07', 7);",
|
|
"insert into ct2 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct3 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct3 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct3 values ('2025-01-01 00:00:02', 6);",
|
|
"insert into ct3 values ('2025-01-01 00:00:03', 0);",
|
|
"insert into ct3 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:05', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:06', 7);",
|
|
"insert into ct3 values ('2025-01-01 00:00:07', 7);",
|
|
"insert into ct3 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct4 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct4 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct4 values ('2025-01-01 00:00:02', 6);",
|
|
"insert into ct4 values ('2025-01-01 00:00:03', 0);",
|
|
"insert into ct4 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:05', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:06', 7);",
|
|
"insert into ct4 values ('2025-01-01 00:00:07', 7);",
|
|
"insert into ct4 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:09', 3);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check1(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name="res_ct1"',
|
|
func=lambda: tdSql.getRows() == 1,
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"',
|
|
func=lambda: tdSql.getRows() == 3,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_ct1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:03")
|
|
and tdSql.compareData(0, 2, 3)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:04")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(1, 2, 2)
|
|
and tdSql.compareData(1, 3, 2)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(2, 2, 1)
|
|
and tdSql.compareData(2, 3, 2)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct4",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:03")
|
|
and tdSql.compareData(0, 2, 3)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:04")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(1, 2, 2)
|
|
and tdSql.compareData(1, 3, 2)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(2, 2, 1)
|
|
and tdSql.compareData(2, 3, 2)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
class Basic5(StreamCheckItem):
|
|
def __init__(self):
|
|
self.db = "sdb5"
|
|
self.stbName = "stb"
|
|
|
|
def create(self):
|
|
tdSql.execute(f"create database {self.db} vgroups 1 buffer 8")
|
|
tdSql.execute(f"use {self.db}")
|
|
tdSql.execute(f"create table if not exists {self.stbName} (cts timestamp, cint int) tags (tint int)")
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(1)
|
|
|
|
tdSql.execute(f"create table ct1 using stb tags(1)")
|
|
tdSql.execute(f"create table ct2 using stb tags(2)")
|
|
tdSql.execute(f"create table ct3 using stb tags(2)")
|
|
tdSql.execute(f"create table ct4 using stb tags(2)")
|
|
|
|
tdSql.query(f"show tables")
|
|
tdSql.checkRows(4)
|
|
|
|
tdLog.info(f"start insert into history data")
|
|
sqls = [
|
|
"insert into ct1 values ('2024-01-01 00:00:00', 0);",
|
|
"insert into ct1 values ('2024-01-01 00:00:01', 0);",
|
|
"insert into ct1 values ('2024-01-01 00:00:02', 1);",
|
|
"insert into ct1 values ('2024-01-01 00:00:03', 1);",
|
|
"insert into ct1 values ('2024-01-01 00:00:04', 1);",
|
|
"insert into ct1 values ('2024-01-01 00:00:05', 2);",
|
|
"insert into ct1 values ('2024-01-01 00:00:06', 2);",
|
|
"insert into ct1 values ('2024-01-01 00:00:07', 2);",
|
|
"insert into ct1 values ('2024-01-01 00:00:08', 2);",
|
|
"insert into ct1 values ('2024-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct2 values ('2024-01-01 00:00:00', 0);",
|
|
"insert into ct2 values ('2024-01-01 00:00:01', 0);",
|
|
"insert into ct2 values ('2024-01-01 00:00:02', 1);",
|
|
"insert into ct2 values ('2024-01-01 00:00:03', 1);",
|
|
"insert into ct2 values ('2024-01-01 00:00:04', 1);",
|
|
"insert into ct2 values ('2024-01-01 00:00:05', 2);",
|
|
"insert into ct2 values ('2024-01-01 00:00:06', 2);",
|
|
"insert into ct2 values ('2024-01-01 00:00:07', 2);",
|
|
"insert into ct2 values ('2024-01-01 00:00:08', 2);",
|
|
"insert into ct2 values ('2024-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct3 values ('2024-01-01 00:00:00', 0);",
|
|
"insert into ct3 values ('2024-01-01 00:00:01', 0);",
|
|
"insert into ct3 values ('2024-01-01 00:00:02', 1);",
|
|
"insert into ct3 values ('2024-01-01 00:00:03', 1);",
|
|
"insert into ct3 values ('2024-01-01 00:00:04', 1);",
|
|
"insert into ct3 values ('2024-01-01 00:00:05', 2);",
|
|
"insert into ct3 values ('2024-01-01 00:00:06', 2);",
|
|
"insert into ct3 values ('2024-01-01 00:00:07', 2);",
|
|
"insert into ct3 values ('2024-01-01 00:00:08', 2);",
|
|
"insert into ct3 values ('2024-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct4 values ('2024-01-01 00:00:00', 0);",
|
|
"insert into ct4 values ('2024-01-01 00:00:01', 0);",
|
|
"insert into ct4 values ('2024-01-01 00:00:02', 1);",
|
|
"insert into ct4 values ('2024-01-01 00:00:03', 1);",
|
|
"insert into ct4 values ('2024-01-01 00:00:04', 1);",
|
|
"insert into ct4 values ('2024-01-01 00:00:05', 2);",
|
|
"insert into ct4 values ('2024-01-01 00:00:06', 2);",
|
|
"insert into ct4 values ('2024-01-01 00:00:07', 2);",
|
|
"insert into ct4 values ('2024-01-01 00:00:08', 2);",
|
|
"insert into ct4 values ('2024-01-01 00:00:09', 3);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
tdSql.execute(
|
|
f"create stream s5 state_window(cint) from ct1 options(fill_history) into res_ct1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
tdSql.execute(
|
|
f"create stream s5_g state_window(cint) from {self.stbName} partition by tbname, tint options(fill_history) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
def insert1(self):
|
|
sqls = [
|
|
"insert into ct1 values ('2024-12-31 00:00:00', 3);",
|
|
"insert into ct1 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct2 values ('2024-12-31 00:00:00', 3);",
|
|
"insert into ct2 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct3 values ('2024-12-31 00:00:00', 3);",
|
|
"insert into ct3 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct3 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct3 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct4 values ('2024-12-31 00:00:00', 3);",
|
|
"insert into ct4 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct4 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct4 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:09', 3);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check1(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name="res_ct1"',
|
|
func=lambda: tdSql.getRows() == 1,
|
|
)
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"',
|
|
func=lambda: tdSql.getRows() == 4,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_ct1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1",
|
|
func=lambda: tdSql.getRows() == 7
|
|
and tdSql.compareData(0, 0, "2024-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2024-01-01 00:00:01")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(4, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(4, 1, "2025-01-01 00:00:01")
|
|
and tdSql.compareData(4, 2, 2)
|
|
and tdSql.compareData(4, 3, 0)
|
|
and tdSql.compareData(4, 4, 0)
|
|
and tdSql.compareData(6, 0, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(6, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(6, 2, 4)
|
|
and tdSql.compareData(6, 3, 8)
|
|
and tdSql.compareData(6, 4, 2),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct3",
|
|
func=lambda: tdSql.getRows() == 7
|
|
and tdSql.compareData(0, 0, "2024-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2024-01-01 00:00:01")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(4, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(4, 1, "2025-01-01 00:00:01")
|
|
and tdSql.compareData(4, 2, 2)
|
|
and tdSql.compareData(4, 3, 0)
|
|
and tdSql.compareData(4, 4, 0)
|
|
and tdSql.compareData(6, 0, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(6, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(6, 2, 4)
|
|
and tdSql.compareData(6, 3, 8)
|
|
and tdSql.compareData(6, 4, 2),
|
|
)
|
|
|
|
class Basic6(StreamCheckItem):
|
|
def __init__(self):
|
|
self.db = "sdb6"
|
|
self.stbName = "stb"
|
|
|
|
def create(self):
|
|
tdSql.execute(f"create database {self.db} vgroups 1 buffer 8")
|
|
tdSql.execute(f"use {self.db}")
|
|
tdSql.execute(f"create table if not exists {self.stbName} (cts timestamp, cint int) tags (tint int)")
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(1)
|
|
|
|
tdSql.execute(f"create table ct1 using stb tags(1)")
|
|
tdSql.execute(f"create table ct2 using stb tags(2)")
|
|
tdSql.execute(f"create table ct3 using stb tags(3)")
|
|
tdSql.execute(f"create table ct4 using stb tags(4)")
|
|
|
|
tdSql.query(f"show tables")
|
|
tdSql.checkRows(4)
|
|
|
|
tdLog.info(f"start insert into history data")
|
|
sqls = [
|
|
"insert into ct1 values ('2024-01-01 00:00:00', 0);",
|
|
"insert into ct1 values ('2024-01-01 00:00:01', 0);",
|
|
"insert into ct1 values ('2024-01-01 00:00:02', 1);",
|
|
"insert into ct1 values ('2024-01-01 00:00:03', 1);",
|
|
"insert into ct1 values ('2024-01-01 00:00:04', 1);",
|
|
"insert into ct1 values ('2024-01-01 00:00:05', 2);",
|
|
"insert into ct1 values ('2024-01-01 00:00:06', 2);",
|
|
"insert into ct1 values ('2024-01-01 00:00:07', 2);",
|
|
"insert into ct1 values ('2024-01-01 00:00:08', 2);",
|
|
"insert into ct1 values ('2024-01-01 00:00:09', 3);",
|
|
"insert into ct1 values ('2024-01-02 00:00:00', 0);",
|
|
"insert into ct1 values ('2024-01-02 00:00:01', 0);",
|
|
"insert into ct1 values ('2024-01-02 00:00:02', 1);",
|
|
"insert into ct1 values ('2024-01-02 00:00:03', 1);",
|
|
"insert into ct1 values ('2024-01-02 00:00:04', 1);",
|
|
"insert into ct1 values ('2024-01-02 00:00:05', 2);",
|
|
"insert into ct1 values ('2024-01-02 00:00:06', 2);",
|
|
"insert into ct1 values ('2024-01-02 00:00:07', 2);",
|
|
"insert into ct1 values ('2024-01-02 00:00:08', 2);",
|
|
"insert into ct1 values ('2024-01-02 00:00:09', 3);",
|
|
|
|
"insert into ct2 values ('2024-01-01 00:00:00', 0);",
|
|
"insert into ct2 values ('2024-01-01 00:00:01', 0);",
|
|
"insert into ct2 values ('2024-01-01 00:00:02', 1);",
|
|
"insert into ct2 values ('2024-01-01 00:00:03', 1);",
|
|
"insert into ct2 values ('2024-01-01 00:00:04', 1);",
|
|
"insert into ct2 values ('2024-01-01 00:00:05', 2);",
|
|
"insert into ct2 values ('2024-01-01 00:00:06', 2);",
|
|
"insert into ct2 values ('2024-01-01 00:00:07', 2);",
|
|
"insert into ct2 values ('2024-01-01 00:00:08', 2);",
|
|
"insert into ct2 values ('2024-01-01 00:00:09', 3);",
|
|
"insert into ct2 values ('2024-01-02 00:00:00', 0);",
|
|
"insert into ct2 values ('2024-01-02 00:00:01', 0);",
|
|
"insert into ct2 values ('2024-01-02 00:00:02', 1);",
|
|
"insert into ct2 values ('2024-01-02 00:00:03', 1);",
|
|
"insert into ct2 values ('2024-01-02 00:00:04', 1);",
|
|
"insert into ct2 values ('2024-01-02 00:00:05', 2);",
|
|
"insert into ct2 values ('2024-01-02 00:00:06', 2);",
|
|
"insert into ct2 values ('2024-01-02 00:00:07', 2);",
|
|
"insert into ct2 values ('2024-01-02 00:00:08', 2);",
|
|
"insert into ct2 values ('2024-01-02 00:00:09', 3);",
|
|
|
|
"insert into ct3 values ('2024-01-01 00:00:00', 0);",
|
|
"insert into ct3 values ('2024-01-01 00:00:01', 0);",
|
|
"insert into ct3 values ('2024-01-01 00:00:02', 1);",
|
|
"insert into ct3 values ('2024-01-01 00:00:03', 1);",
|
|
"insert into ct3 values ('2024-01-01 00:00:04', 1);",
|
|
"insert into ct3 values ('2024-01-01 00:00:05', 2);",
|
|
"insert into ct3 values ('2024-01-01 00:00:06', 2);",
|
|
"insert into ct3 values ('2024-01-01 00:00:07', 2);",
|
|
"insert into ct3 values ('2024-01-01 00:00:08', 2);",
|
|
"insert into ct3 values ('2024-01-01 00:00:09', 3);",
|
|
"insert into ct3 values ('2024-01-02 00:00:00', 0);",
|
|
"insert into ct3 values ('2024-01-02 00:00:01', 0);",
|
|
"insert into ct3 values ('2024-01-02 00:00:02', 1);",
|
|
"insert into ct3 values ('2024-01-02 00:00:03', 1);",
|
|
"insert into ct3 values ('2024-01-02 00:00:04', 1);",
|
|
"insert into ct3 values ('2024-01-02 00:00:05', 2);",
|
|
"insert into ct3 values ('2024-01-02 00:00:06', 2);",
|
|
"insert into ct3 values ('2024-01-02 00:00:07', 2);",
|
|
"insert into ct3 values ('2024-01-02 00:00:08', 2);",
|
|
"insert into ct3 values ('2024-01-02 00:00:09', 3);",
|
|
|
|
"insert into ct4 values ('2024-01-01 00:00:00', 0);",
|
|
"insert into ct4 values ('2024-01-01 00:00:01', 0);",
|
|
"insert into ct4 values ('2024-01-01 00:00:02', 1);",
|
|
"insert into ct4 values ('2024-01-01 00:00:03', 1);",
|
|
"insert into ct4 values ('2024-01-01 00:00:04', 1);",
|
|
"insert into ct4 values ('2024-01-01 00:00:05', 2);",
|
|
"insert into ct4 values ('2024-01-01 00:00:06', 2);",
|
|
"insert into ct4 values ('2024-01-01 00:00:07', 2);",
|
|
"insert into ct4 values ('2024-01-01 00:00:08', 2);",
|
|
"insert into ct4 values ('2024-01-01 00:00:09', 3);",
|
|
"insert into ct4 values ('2024-01-02 00:00:00', 0);",
|
|
"insert into ct4 values ('2024-01-02 00:00:01', 0);",
|
|
"insert into ct4 values ('2024-01-02 00:00:02', 1);",
|
|
"insert into ct4 values ('2024-01-02 00:00:03', 1);",
|
|
"insert into ct4 values ('2024-01-02 00:00:04', 1);",
|
|
"insert into ct4 values ('2024-01-02 00:00:05', 2);",
|
|
"insert into ct4 values ('2024-01-02 00:00:06', 2);",
|
|
"insert into ct4 values ('2024-01-02 00:00:07', 2);",
|
|
"insert into ct4 values ('2024-01-02 00:00:08', 2);",
|
|
"insert into ct4 values ('2024-01-02 00:00:09', 3);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
tdSql.execute(
|
|
f"create stream s6 state_window(cint) from ct1 options(fill_history('2024-01-02 00:00:00')) into res_ct1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
tdSql.execute(
|
|
f"create stream s6_g state_window(cint) from {self.stbName} partition by tbname, tint options(fill_history('2024-01-02 00:00:00')) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
def insert1(self):
|
|
sqls = [
|
|
"insert into ct1 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct2 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct3 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct3 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct3 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct3 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct3 values ('2025-01-01 00:00:09', 3);",
|
|
|
|
"insert into ct4 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct4 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct4 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct4 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct4 values ('2025-01-01 00:00:09', 3);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check1(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name="res_ct1"',
|
|
func=lambda: tdSql.getRows() == 1,
|
|
)
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_ct%"',
|
|
func=lambda: tdSql.getRows() == 4,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_ct1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1",
|
|
func=lambda: tdSql.getRows() == 7
|
|
and tdSql.compareData(0, 0, "2024-01-02 00:00:00")
|
|
and tdSql.compareData(0, 1, "2024-01-02 00:00:01")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(4, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(4, 1, "2025-01-01 00:00:01")
|
|
and tdSql.compareData(4, 2, 2)
|
|
and tdSql.compareData(4, 3, 0)
|
|
and tdSql.compareData(4, 4, 0)
|
|
and tdSql.compareData(6, 0, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(6, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(6, 2, 4)
|
|
and tdSql.compareData(6, 3, 8)
|
|
and tdSql.compareData(6, 4, 2),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct4",
|
|
func=lambda: tdSql.getRows() == 7
|
|
and tdSql.compareData(0, 0, "2024-01-02 00:00:00")
|
|
and tdSql.compareData(0, 1, "2024-01-02 00:00:01")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(4, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(4, 1, "2025-01-01 00:00:01")
|
|
and tdSql.compareData(4, 2, 2)
|
|
and tdSql.compareData(4, 3, 0)
|
|
and tdSql.compareData(4, 4, 0)
|
|
and tdSql.compareData(6, 0, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(6, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(6, 2, 4)
|
|
and tdSql.compareData(6, 3, 8)
|
|
and tdSql.compareData(6, 4, 2),
|
|
)
|
|
|
|
class Basic7(StreamCheckItem):
|
|
def __init__(self):
|
|
self.db = "sdb7"
|
|
self.stbName = "stb"
|
|
|
|
def create(self):
|
|
tdSql.execute(f"create database {self.db} vgroups 1 buffer 8")
|
|
tdSql.execute(f"use {self.db}")
|
|
tdSql.execute(f"create table if not exists {self.stbName} (cts timestamp, cint int) tags (tint int)")
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(1)
|
|
|
|
tdSql.execute(f"create table ct1 using stb tags(1)")
|
|
tdSql.execute(f"create table ct2 using stb tags(2)")
|
|
|
|
tdSql.query(f"show tables")
|
|
tdSql.checkRows(2)
|
|
|
|
tdSql.execute(
|
|
f"create stream s7 state_window(cint) from ct1 options(delete_recalc) into res_ct1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
tdSql.execute(
|
|
f"create stream s7_g state_window(cint) from {self.stbName} partition by tbname, tint options(delete_recalc) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
def insert1(self):
|
|
sqls = [
|
|
"insert into ct1 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:09', 3);",
|
|
"insert into ct1 values ('2025-01-01 00:00:10', 3);",
|
|
"insert into ct1 values ('2025-01-01 00:00:11', 3);",
|
|
"insert into ct1 values ('2025-01-01 00:00:12', 4);",
|
|
|
|
"insert into ct2 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:02', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:03', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:04', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:05', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:06', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:07', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:08', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:09', 3);",
|
|
"insert into ct2 values ('2025-01-01 00:00:10', 3);",
|
|
"insert into ct2 values ('2025-01-01 00:00:11', 3);",
|
|
"insert into ct2 values ('2025-01-01 00:00:12', 4);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check1(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and (table_name="res_ct1" or table_name="res_stb_ct1" or table_name="res_stb_ct2")',
|
|
func=lambda: tdSql.getRows() == 3,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_ct1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1",
|
|
func=lambda: tdSql.getRows() == 4
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:01")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:02")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:04")
|
|
and tdSql.compareData(1, 2, 3)
|
|
and tdSql.compareData(1, 3, 3)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(2, 2, 4)
|
|
and tdSql.compareData(2, 3, 8)
|
|
and tdSql.compareData(2, 4, 2)
|
|
and tdSql.compareData(3, 0, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(3, 1, "2025-01-01 00:00:11")
|
|
and tdSql.compareData(3, 2, 3)
|
|
and tdSql.compareData(3, 3, 9)
|
|
and tdSql.compareData(3, 4, 3),
|
|
)
|
|
|
|
def insert2(self):
|
|
sqls = [
|
|
"delete from ct1 where cts >= '2025-01-01 00:00:00' and cts <= '2025-01-01 00:00:01';",
|
|
"delete from ct1 where cts = '2025-01-01 00:00:02';",
|
|
"delete from ct1 where cts = '2025-01-01 00:00:06';",
|
|
"delete from ct1 where cts = '2025-01-01 00:00:11';",
|
|
"delete from ct2 where cts >= '2025-01-01 00:00:00' and cts <= '2025-01-01 00:00:01';",
|
|
"delete from ct2 where cts = '2025-01-01 00:00:02';",
|
|
"delete from ct2 where cts = '2025-01-01 00:00:06';",
|
|
"delete from ct2 where cts = '2025-01-01 00:00:11';",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check2(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name="res_ct1"',
|
|
func=lambda: tdSql.getRows() == 1,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_ct1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:03")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:04")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 2)
|
|
and tdSql.compareData(0, 4, 1)
|
|
and tdSql.compareData(4, 0, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(4, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(4, 2, 3)
|
|
and tdSql.compareData(4, 3, 6)
|
|
and tdSql.compareData(4, 4, 2)
|
|
and tdSql.compareData(6, 0, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(6, 1, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(6, 2, 2)
|
|
and tdSql.compareData(6, 3, 6)
|
|
and tdSql.compareData(6, 4, 3),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:03")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:04")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 2)
|
|
and tdSql.compareData(0, 4, 1)
|
|
and tdSql.compareData(4, 0, "2025-01-01 00:00:05")
|
|
and tdSql.compareData(4, 1, "2025-01-01 00:00:08")
|
|
and tdSql.compareData(4, 2, 3)
|
|
and tdSql.compareData(4, 3, 6)
|
|
and tdSql.compareData(4, 4, 2)
|
|
and tdSql.compareData(6, 0, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(6, 1, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(6, 2, 2)
|
|
and tdSql.compareData(6, 3, 6)
|
|
and tdSql.compareData(6, 4, 3),
|
|
)
|
|
|
|
class Basic8(StreamCheckItem):
|
|
def __init__(self):
|
|
self.db = "sdb8"
|
|
self.stbName = "stb"
|
|
|
|
def create(self):
|
|
tdSql.execute(f"create database {self.db} vgroups 1 buffer 8")
|
|
tdSql.execute(f"use {self.db}")
|
|
tdSql.execute(f"create table if not exists {self.stbName} (cts timestamp, cint int) tags (tint int)")
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(1)
|
|
|
|
tdSql.execute(f"create table ct1 using stb tags(1)")
|
|
tdSql.execute(f"create table ct2 using stb tags(2)")
|
|
|
|
tdSql.query(f"show tables")
|
|
tdSql.checkRows(2)
|
|
|
|
tdSql.execute(
|
|
f"create stream s8 state_window(cint) from ct1 options(ignore_disorder) into res_ct1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
tdSql.execute(
|
|
f"create stream s8_1 state_window(cint) from ct1 into res_ct1_1 (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
tdSql.execute(
|
|
f"create stream s8_g state_window(cint) from {self.stbName} partition by tbname, tint options(ignore_disorder) into res_stb OUTPUT_SUBTABLE(CONCAT('res_stb_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
tdSql.execute(
|
|
f"create stream s8_g_1 state_window(cint) from {self.stbName} partition by tbname, tint into res_stb_1 OUTPUT_SUBTABLE(CONCAT('res_stb_1_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from %%trows;"
|
|
)
|
|
|
|
def insert1(self):
|
|
sqls = [
|
|
"insert into ct1 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:09', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:10', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:19', 1);",
|
|
"insert into ct1 values ('2025-01-01 00:00:20', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:29', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:40', 6);",
|
|
|
|
"insert into ct2 values ('2025-01-01 00:00:00', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:09', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:10', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:19', 1);",
|
|
"insert into ct2 values ('2025-01-01 00:00:20', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:29', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:40', 6);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check1(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and (table_name like "res_%")',
|
|
func=lambda: tdSql.getRows() == 6,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_ct1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(1, 2, 2)
|
|
and tdSql.compareData(1, 3, 2)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:20")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:29")
|
|
and tdSql.compareData(2, 2, 2)
|
|
and tdSql.compareData(2, 3, 4)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1_1",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(1, 2, 2)
|
|
and tdSql.compareData(1, 3, 2)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:20")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:29")
|
|
and tdSql.compareData(2, 2, 2)
|
|
and tdSql.compareData(2, 3, 4)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct1",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(1, 2, 2)
|
|
and tdSql.compareData(1, 3, 2)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:20")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:29")
|
|
and tdSql.compareData(2, 2, 2)
|
|
and tdSql.compareData(2, 3, 4)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_1_ct2",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(1, 2, 2)
|
|
and tdSql.compareData(1, 3, 2)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:20")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:29")
|
|
and tdSql.compareData(2, 2, 2)
|
|
and tdSql.compareData(2, 3, 4)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
def insert2(self):
|
|
sqls = [
|
|
"insert into ct1 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:08', 0);",
|
|
"insert into ct1 values ('2025-01-01 00:00:11', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:18', 2);",
|
|
"insert into ct1 values ('2025-01-01 00:00:20', 4);",
|
|
"insert into ct1 values ('2025-01-01 00:00:29', 4);",
|
|
"insert into ct1 values ('2025-01-01 00:00:30', 3);",
|
|
|
|
"insert into ct2 values ('2025-01-01 00:00:01', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:08', 0);",
|
|
"insert into ct2 values ('2025-01-01 00:00:11', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:18', 2);",
|
|
"insert into ct2 values ('2025-01-01 00:00:20', 4);",
|
|
"insert into ct2 values ('2025-01-01 00:00:29', 4);",
|
|
"insert into ct2 values ('2025-01-01 00:00:30', 3);",
|
|
]
|
|
tdSql.executes(sqls)
|
|
|
|
def check2(self):
|
|
tdSql.checkResultsByFunc(
|
|
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_%"',
|
|
func=lambda: tdSql.getRows() == 6,
|
|
)
|
|
|
|
tdSql.checkTableSchema(
|
|
dbname=self.db,
|
|
tbname="res_ct1_1",
|
|
schema=[
|
|
["firstts", "TIMESTAMP", 8, ""],
|
|
["lastts", "TIMESTAMP", 8, ""],
|
|
["cnt_v", "BIGINT", 8, ""],
|
|
["sum_v", "BIGINT", 8, ""],
|
|
["avg_v", "DOUBLE", 8, ""],
|
|
],
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(1, 2, 2)
|
|
and tdSql.compareData(1, 3, 2)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:20")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:29")
|
|
and tdSql.compareData(2, 2, 2)
|
|
and tdSql.compareData(2, 3, 4)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_ct1_1",
|
|
func=lambda: tdSql.getRows() == 6
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(0, 2, 4)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 2, 1)
|
|
and tdSql.compareData(1, 3, 1)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:11")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:18")
|
|
and tdSql.compareData(2, 2, 2)
|
|
and tdSql.compareData(2, 3, 4)
|
|
and tdSql.compareData(2, 4, 2)
|
|
and tdSql.compareData(3, 0, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(3, 1, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(3, 2, 1)
|
|
and tdSql.compareData(3, 3, 1)
|
|
and tdSql.compareData(3, 4, 1)
|
|
and tdSql.compareData(4, 0, "2025-01-01 00:00:20")
|
|
and tdSql.compareData(4, 1, "2025-01-01 00:00:29")
|
|
and tdSql.compareData(4, 2, 2)
|
|
and tdSql.compareData(4, 3, 8)
|
|
and tdSql.compareData(4, 4, 4)
|
|
and tdSql.compareData(3, 0, "2025-01-01 00:00:30")
|
|
and tdSql.compareData(3, 1, "2025-01-01 00:00:30")
|
|
and tdSql.compareData(3, 2, 1)
|
|
and tdSql.compareData(3, 3, 3)
|
|
and tdSql.compareData(3, 4, 3),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_ct2",
|
|
func=lambda: tdSql.getRows() == 3
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(0, 2, 2)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(1, 2, 2)
|
|
and tdSql.compareData(1, 3, 2)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:20")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:29")
|
|
and tdSql.compareData(2, 2, 2)
|
|
and tdSql.compareData(2, 3, 4)
|
|
and tdSql.compareData(2, 4, 2),
|
|
)
|
|
|
|
tdSql.checkResultsByFunc(
|
|
sql=f"select firstts, lastts, cnt_v, sum_v, avg_v from {self.db}.res_stb_1_ct2",
|
|
func=lambda: tdSql.getRows() == 6
|
|
and tdSql.compareData(0, 0, "2025-01-01 00:00:00")
|
|
and tdSql.compareData(0, 1, "2025-01-01 00:00:09")
|
|
and tdSql.compareData(0, 2, 4)
|
|
and tdSql.compareData(0, 3, 0)
|
|
and tdSql.compareData(0, 4, 0)
|
|
and tdSql.compareData(1, 0, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 1, "2025-01-01 00:00:10")
|
|
and tdSql.compareData(1, 2, 1)
|
|
and tdSql.compareData(1, 3, 1)
|
|
and tdSql.compareData(1, 4, 1)
|
|
and tdSql.compareData(2, 0, "2025-01-01 00:00:11")
|
|
and tdSql.compareData(2, 1, "2025-01-01 00:00:18")
|
|
and tdSql.compareData(2, 2, 2)
|
|
and tdSql.compareData(2, 3, 4)
|
|
and tdSql.compareData(2, 4, 2)
|
|
and tdSql.compareData(3, 0, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(3, 1, "2025-01-01 00:00:19")
|
|
and tdSql.compareData(3, 2, 1)
|
|
and tdSql.compareData(3, 3, 1)
|
|
and tdSql.compareData(3, 4, 1)
|
|
and tdSql.compareData(4, 0, "2025-01-01 00:00:20")
|
|
and tdSql.compareData(4, 1, "2025-01-01 00:00:29")
|
|
and tdSql.compareData(4, 2, 2)
|
|
and tdSql.compareData(4, 3, 8)
|
|
and tdSql.compareData(4, 4, 4)
|
|
and tdSql.compareData(3, 0, "2025-01-01 00:00:30")
|
|
and tdSql.compareData(3, 1, "2025-01-01 00:00:30")
|
|
and tdSql.compareData(3, 2, 1)
|
|
and tdSql.compareData(3, 3, 3)
|
|
and tdSql.compareData(3, 4, 3),
|
|
)
|
|
|