mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
410 lines
16 KiB
Python
410 lines
16 KiB
Python
from new_test_framework.utils import tdLog, tdSql, sc, clusterComCheck
|
|
|
|
|
|
class TestFuncStddev2:
|
|
|
|
def setup_class(cls):
|
|
tdLog.debug(f"start to execute {__file__}")
|
|
|
|
def test_func_stddev2(self):
|
|
"""Stddev
|
|
|
|
1. -
|
|
|
|
Catalog:
|
|
- Function:Aggregate
|
|
|
|
Since: v3.0.0.0
|
|
|
|
Labels: common,ci
|
|
|
|
Jira: None
|
|
|
|
History:
|
|
- 2025-4-28 Simon Guan Migrated from tsim/query/stddev.sim
|
|
|
|
"""
|
|
|
|
tdLog.info(f"=============== create database")
|
|
tdSql.execute(f"create database db")
|
|
tdSql.query(f"select * from information_schema.ins_databases")
|
|
tdSql.checkRows(3)
|
|
|
|
tdSql.execute(f"use db")
|
|
|
|
tdLog.info(f"=============== create super table and child table")
|
|
tdSql.execute(
|
|
f"create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int)"
|
|
)
|
|
tdSql.query(f"show stables")
|
|
tdSql.checkRows(1)
|
|
|
|
tdSql.execute(f"create table ct1 using stb1 tags ( 1 )")
|
|
tdSql.execute(f"create table ct2 using stb1 tags ( 2 )")
|
|
tdSql.execute(f"create table ct3 using stb1 tags ( 3 )")
|
|
tdSql.execute(f"create table ct4 using stb1 tags ( 4 )")
|
|
tdSql.query(f"show tables")
|
|
tdLog.info(
|
|
f"{tdSql.getRows()}) {tdSql.getData(0,0)} {tdSql.getData(1,0)} {tdSql.getData(2,0)}"
|
|
)
|
|
tdSql.checkRows(4)
|
|
|
|
tdSql.execute(
|
|
f"create table t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)"
|
|
)
|
|
|
|
tdLog.info(f"=============== insert data into child table ct1 (s)")
|
|
tdSql.execute(
|
|
f'insert into ct1 values ( \'2022-01-01 01:01:01.000\', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct1 values ( \'2022-01-01 01:01:06.000\', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct1 values ( \'2022-01-01 01:01:10.000\', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct1 values ( \'2022-01-01 01:01:16.000\', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct1 values ( \'2022-01-01 01:01:20.000\', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct1 values ( \'2022-01-01 01:01:26.000\', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct1 values ( \'2022-01-01 01:01:30.000\', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct1 values ( \'2022-01-01 01:01:36.000\', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a )'
|
|
)
|
|
|
|
tdLog.info(f"=============== insert data into child table ct4 (y)")
|
|
tdSql.execute(
|
|
f"insert into ct4 values ( '2019-01-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )"
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct4 values ( \'2019-10-21 01:01:01.000\', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct4 values ( \'2019-12-31 01:01:01.000\', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct4 values ( \'2020-01-01 01:01:06.000\', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct4 values ( \'2020-05-07 01:01:10.000\', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct4 values ( \'2020-09-30 01:01:16.000\', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a )'
|
|
)
|
|
tdSql.execute(
|
|
f"insert into ct4 values ( '2020-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )"
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct4 values ( \'2021-02-01 01:01:20.000\', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct4 values ( \'2021-10-28 01:01:26.000\', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into ct4 values ( \'2021-12-01 01:01:30.000\', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" )'
|
|
)
|
|
# tdSql.execute(
|
|
# f'insert into ct4 values ( \'2022-02-31 01:01:36.000\', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" )'
|
|
# )
|
|
tdSql.execute(
|
|
f"insert into ct4 values ( '2022-05-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )"
|
|
)
|
|
|
|
tdLog.info(f"=============== insert data into child table t1")
|
|
tdSql.execute(
|
|
f'insert into t1 values ( \'2020-10-21 01:01:01.000\', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into t1 values ( \'2020-12-31 01:01:01.000\', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into t1 values ( \'2021-01-01 01:01:06.000\', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into t1 values ( \'2021-05-07 01:01:10.000\', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into t1 values ( \'2021-09-30 01:01:16.000\', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into t1 values ( \'2022-02-01 01:01:20.000\', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into t1 values ( \'2022-10-28 01:01:26.000\', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into t1 values ( \'2022-12-01 01:01:30.000\', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" )'
|
|
)
|
|
tdSql.execute(
|
|
f'insert into t1 values ( \'2022-12-31 01:01:36.000\', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" )'
|
|
)
|
|
|
|
tdLog.info(f"================ start query ======================")
|
|
|
|
tdLog.info(f"=============== step1")
|
|
tdLog.info(f"=====sql : select stddev(c1) as b from ct4")
|
|
tdSql.query(f"select stddev(c1) as b from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1) as b from t1")
|
|
tdSql.query(f"select stddev(c1) as b from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select _wstart, stddev(c1) as b from ct4 interval(1y)")
|
|
tdSql.query(f"select _wstart, stddev(c1) as b from ct4 interval(1y)")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(4)
|
|
|
|
tdLog.info(f"=====sql : select _wstart, stddev(c1) as b from t1 interval(1y)")
|
|
tdSql.query(f"select _wstart, stddev(c1) as b from t1 interval(1y)")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(3)
|
|
|
|
tdLog.info(
|
|
f"=====select _wstart, stddev(c1) as b from ct4 where c1 <= 6 interval(180d)"
|
|
)
|
|
tdSql.query(
|
|
f"select _wstart, stddev(c1) as b from ct4 where c1 <= 6 interval(180d)"
|
|
)
|
|
# print ===> $rows
|
|
# if $rows != 3 then
|
|
# return -1
|
|
# endi
|
|
|
|
tdLog.info(
|
|
f"=====select _wstart, stddev(c1) as b from t1 where c1 <= 6 interval(180d)"
|
|
)
|
|
tdSql.query(
|
|
f"select _wstart, stddev(c1) as b from t1 where c1 <= 6 interval(180d)"
|
|
)
|
|
# print ===> $rows
|
|
# if $rows != 3 then
|
|
# return -1
|
|
# endi
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1) a1, sum(c1) b1 from ct4")
|
|
tdSql.query(f"select stddev(c1) a1, sum(c1) b1 from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1) a1, sum(c1) b1 from t1")
|
|
tdSql.query(f"select stddev(c1) a1, sum(c1) b1 from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1)+sum(c1) b1 from ct4")
|
|
tdSql.query(f" select stddev(c1)+sum(c1) b1 from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1)+sum(c1) b1 from t1")
|
|
tdSql.query(f" select stddev(c1)+sum(c1) b1 from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c2) from ct4")
|
|
tdSql.query(f" select stddev(c2) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c2) from t1")
|
|
tdSql.query(f" select stddev(c2) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c3) from ct4")
|
|
tdSql.query(f" select stddev(c3) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c3) from t1")
|
|
tdSql.query(f" select stddev(c3) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c4) from ct4")
|
|
tdSql.query(f" select stddev(c4) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c4) from t1")
|
|
tdSql.query(f" select stddev(c4) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c5) from ct4")
|
|
tdSql.query(f" select stddev(c5) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c5) from t1")
|
|
tdSql.query(f" select stddev(c5) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c6) from ct4")
|
|
tdSql.query(f" select stddev(c6) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c6) from t1")
|
|
tdSql.query(f" select stddev(c6) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c7) from ct4")
|
|
tdSql.error(f" select stddev(c7) from ct4")
|
|
# print ===> $rows
|
|
# if $rows != 1 then
|
|
# return -1
|
|
# endi
|
|
|
|
tdLog.info(f"=====sql : select stddev(c7) from t1")
|
|
tdSql.error(f" select stddev(c7) from t1")
|
|
# print ===> $rows
|
|
# if $rows != 1 then
|
|
# return -1
|
|
# endi
|
|
|
|
# =================================================
|
|
tdLog.info(f"=============== stop and restart taosd")
|
|
sc.dnodeStop(1)
|
|
sc.dnodeStart(1)
|
|
clusterComCheck.checkDnodes(1)
|
|
|
|
tdLog.info(f"=============== step2 after wal")
|
|
tdLog.info(f"=====sql : select stddev(c1) as b from ct4")
|
|
tdSql.query(f"select stddev(c1) as b from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1) as b from t1")
|
|
tdSql.query(f"select stddev(c1) as b from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select _wstart, stddev(c1) as b from ct4 interval(1y)")
|
|
tdSql.query(f"select _wstart, stddev(c1) as b from ct4 interval(1y)")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(4)
|
|
|
|
tdLog.info(f"=====sql : select _wstart, stddev(c1) as b from t1 interval(1y)")
|
|
tdSql.query(f"select _wstart, stddev(c1) as b from t1 interval(1y)")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(3)
|
|
|
|
tdLog.info(
|
|
f"=====select _wstart, stddev(c1) as b from ct4 where c1 <= 6 interval(180d)"
|
|
)
|
|
tdSql.query(
|
|
f"select _wstart, stddev(c1) as b from ct4 where c1 <= 6 interval(180d)"
|
|
)
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(3)
|
|
|
|
tdLog.info(
|
|
f"=====select _wstart, stddev(c1) as b from t1 where c1 <= 6 interval(180d)"
|
|
)
|
|
tdSql.query(
|
|
f"select _wstart, stddev(c1) as b from t1 where c1 <= 6 interval(180d)"
|
|
)
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(3)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1) a1, sum(c1) b1 from ct4")
|
|
tdSql.query(f"select stddev(c1) a1, sum(c1) b1 from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1) a1, sum(c1) b1 from t1")
|
|
tdSql.query(f"select stddev(c1) a1, sum(c1) b1 from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1)+sum(c1) b1 from ct4")
|
|
tdSql.query(f" select stddev(c1)+sum(c1) b1 from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c1)+sum(c1) b1 from t1")
|
|
tdSql.query(f" select stddev(c1)+sum(c1) b1 from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c2) from ct4")
|
|
tdSql.query(f" select stddev(c2) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c2) from t1")
|
|
tdSql.query(f" select stddev(c2) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c3) from ct4")
|
|
tdSql.query(f" select stddev(c3) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c3) from t1")
|
|
tdSql.query(f" select stddev(c3) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c4) from ct4")
|
|
tdSql.query(f" select stddev(c4) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c4) from t1")
|
|
tdSql.query(f" select stddev(c4) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c5) from ct4")
|
|
tdSql.query(f" select stddev(c5) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c5) from t1")
|
|
tdSql.query(f" select stddev(c5) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c6) from ct4")
|
|
tdSql.query(f" select stddev(c6) from ct4")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c6) from t1")
|
|
tdSql.query(f" select stddev(c6) from t1")
|
|
tdLog.info(f"===> {tdSql.getRows()})")
|
|
tdSql.checkRows(1)
|
|
|
|
tdLog.info(f"=====sql : select stddev(c7) from ct4")
|
|
tdSql.error(f" select stddev(c7) from ct4")
|
|
# print ===> $rows
|
|
# if $rows != 1 then
|
|
# return -1
|
|
# endi
|
|
|
|
tdLog.info(f"=====sql : select stddev(c7) from t1")
|
|
tdSql.error(f" select stddev(c7) from t1")
|
|
# print ===> $rows
|
|
# if $rows != 1 then
|
|
# return -1
|
|
# endi
|
|
|
|
tdLog.info(f"=============== clear")
|
|
tdSql.execute(f"drop database db")
|
|
tdSql.query(f"select * from information_schema.ins_databases")
|
|
tdSql.checkRows(2)
|