TDengine/test/cases/10-Functions/03-Selection/test_func_first.py
2025-04-29 18:29:05 +08:00

149 lines
4.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from new_test_framework.utils import tdLog, tdSql, sc, clusterComCheck
class TestFuncFirst:
def setup_class(cls):
tdLog.debug(f"start to execute {__file__}")
def test_func_first(self):
"""First 函数
1. 创建包含一个 Int 普通数据列的超级表
2. 创建子表并写入数据
3. 对子表执行 First 查询,包括时间窗口、普通数据列筛选
4. 对超级表执行 First 查询包括时间窗口、普通数据列筛选、标签列筛选、Group By、Partition By
Catalog:
- Function:Selection
Since: v3.0.0.0
Labels: common,ci
Jira: None
History:
- 2025-4-28 Simon Guan Migrated to new test framework, from tests/script/tsim/compute/first.sim
"""
dbPrefix = "m_fi_db"
tbPrefix = "m_fi_tb"
mtPrefix = "m_fi_mt"
tbNum = 10
rowNum = 20
totalNum = 200
tdLog.info(f"=============== step1")
i = 0
db = dbPrefix + str(i)
mt = mtPrefix + str(i)
tdSql.prepare(db, drop=True)
tdSql.execute(f"use {db}")
tdSql.execute(f"create table {mt} (ts timestamp, tbcol int) TAGS(tgcol int)")
i = 0
while i < tbNum:
tb = tbPrefix + str(i)
tdSql.execute(f"create table {tb} using {mt} tags( {i} )")
x = 0
while x < rowNum:
cc = x * 60000
ms = 1601481600000 + cc
tdSql.execute(f"insert into {tb} values ({ms} , {x} )")
x = x + 1
i = i + 1
tdLog.info(f"=============== step2")
i = 1
tb = tbPrefix + str(i)
tdSql.query(f"select first(tbcol) from {tb}")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdLog.info(f"=============== step3")
cc = 4 * 60000
ms = 1601481600000 + cc
tdSql.query(f"select first(tbcol) from {tb} where ts <= {ms}")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdLog.info(f"=============== step4")
tdSql.query(f"select first(tbcol) as b from {tb}")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdLog.info(f"=============== step5")
tdSql.query(f"select first(tbcol) as b from {tb} interval(1m)")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdSql.query(f"select first(tbcol) as b from {tb} interval(1d)")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdLog.info(f"=============== step6")
cc = 4 * 60000
ms = 1601481600000 + cc
tdSql.query(f"select first(tbcol) as b from {tb} where ts <= {ms} interval(1m)")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(4, 0, 4)
tdSql.checkRows(5)
tdLog.info(f"=============== step7")
tdSql.query(f"select first(tbcol) from {mt}")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdLog.info(f"=============== step8")
cc = 4 * 60000
ms = 1601481600000 + cc
tdSql.query(f"select first(tbcol) as c from {mt} where ts <= {ms}")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdSql.query(f"select first(tbcol) as c from {mt} where tgcol < 5")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
cc = 4 * 60000
ms = 1601481600000 + cc
tdSql.query(
f"select first(tbcol) as c from {mt} where tgcol < 5 and ts <= {ms}"
)
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdLog.info(f"=============== step9")
tdSql.query(f"select first(tbcol) as b from {mt} interval(1m)")
tdLog.info(f"select first(tbcol) as b from {mt} interval(1m)")
tdLog.info(f"===> {tdSql.getData(1,0)}")
tdSql.checkData(1, 0, 1)
tdSql.query(f"select first(tbcol) as b from {mt} interval(1d)")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdLog.info(f"=============== step10")
tdSql.query(f"select first(tbcol) as b from {mt} group by tgcol")
tdLog.info(f"===> {tdSql.getData(0,0)}")
tdSql.checkData(0, 0, 0)
tdSql.checkRows(tbNum)
tdLog.info(f"=============== step11")
cc = 4 * 60000
ms = 1601481600000 + cc
tdSql.query(
f"select first(tbcol) as b from {mt} where ts <= {ms} partition by tgcol interval(1m)"
)
tdLog.info(f"===> {tdSql.getData(1,0)}")
tdSql.checkData(1, 0, 1)
tdSql.checkRows(50)
tdLog.info(f"=============== clear")
tdSql.execute(f"drop database {db}")
tdSql.query(f"select * from information_schema.ins_databases")
tdSql.checkRows(2)