Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: add test case#33759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
facetosea wants to merge1 commit into3.0
base:3.0
Choose a base branch
Loading
fromfix/TS-6102/windowQueryWithoutAggSupport
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletionssource/libs/parser/src/parTranslater.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4644,9 +4644,9 @@ static EDealRes searchAggFuncNode(SNode* pNode, void* pContext) {
}

static int32_t checkWindowGrpFuncCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) {
if (NULL != pSelect->pWindow && !pSelect->hasAggFuncs && !pSelect->hasStateKey) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN);
}
//if (NULL != pSelect->pWindow && !pSelect->hasAggFuncs && !pSelect->hasStateKey) {
// return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN);
//}
Comment on lines +4647 to +4649
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

This block of code is commented out. If it's no longer needed, it should be removed to improve code clarity. Leaving dead code can be confusing for future maintenance.

if (isWindowJoinStmt(pSelect)) {
if (!pSelect->hasAggFuncs && NULL != pSelect->pHaving) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WJOIN_HAVING_EXPR);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,6 +49,8 @@ def test_interval(self):
tdStream.dropAllStreamsAndDbs()
self.ComputeInterval1()
tdStream.dropAllStreamsAndDbs()
self.WithoutAggInterval()
tdStream.dropAllStreamsAndDbs()

def QueryInterval(self):
dbPrefix = "m_in_db"
Expand DownExpand Up@@ -1535,3 +1537,83 @@ def ComputeInterval1(self):

tdSql.checkRows(1)
tdSql.checkData(0, 1, 1)

def WithoutAggInterval(self):
dbPrefix = "m_in_db"
tbPrefix = "m_in_tb"
mtPrefix = "m_in_mt"
tbNum = 10
rowNum = 20
totalNum = 200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

The variabletotalNum is defined but never used. It should be removed to avoid confusion and improve code clarity.


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
Comment on lines +1558 to +1571
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

For better readability and to follow Python best practices, thesewhile loops with manual incrementing can be replaced withfor loops usingrange().

Suggested change
i=0
whilei<tbNum:
tb=tbPrefix+str(i)
tdSql.execute(f"create table{tb} using{mt} tags({i} )")
x=0
whilex<rowNum:
cc=x*60000
ms=1601481600000+cc
tdSql.execute(f"insert into{tb} values ({ms} ,{x} )")
x=x+1
i=i+1
foriinrange(tbNum):
tb=tbPrefix+str(i)
tdSql.execute(f"create table{tb} using{mt} tags({i} )")
forxinrange(rowNum):
cc=x*60000
ms=1601481600000+cc
tdSql.execute(f"insert into{tb} values ({ms} ,{x} )")


tdLog.info(f"=============== step2")
i = 1
tb = tbPrefix + str(i)

sql = "select _wstart, 1, count(tbcol) from m_in_tb1 interval(1m)"
tdSql.query(sql)
tdSql.checkRows(20)

sql = "select _wstart, 1 from m_in_tb1 interval(1m)"
tdSql.query(sql)
tdSql.checkRows(20)

sql = "select _wstart, 1, count(tbcol) from m_in_tb1 interval(5m)"
tdSql.query(sql)
tdSql.checkRows(4)

sql = "select _wstart, 1 from m_in_tb1 interval(5m)"
tdSql.query(sql)
tdSql.checkRows(4)

sql = "select _wstart, 1, tgcol, count(tbcol) from m_in_tb1 interval(5m)"
tdSql.error(sql)

sql = "select _wstart, 1, tgcol from m_in_tb1 interval(5m)"
tdSql.error(sql)

sql = "select _wstart, 1, tgcol, count(tbcol) from m_in_mt0 partition by tbname interval(5m)"
tdSql.query(sql)
tdSql.checkRows(40)

sql = "select _wstart, 1, tgcol from m_in_mt0 partition by tbname interval(5m)"
tdSql.query(sql)
tdSql.checkRows(40)

sql = "select _wstart, 1, tgcol, count(tbcol) from m_in_mt0 partition by tbname interval(5m);"
tdSql.query(sql)
tdSql.checkRows(40)

sql = "select _wstart, _wend, tbname, 1, tgcol, count(tbcol) from m_in_mt0 partition by tbname interval(5m);"
tdSql.query(sql)
tdSql.checkRows(40)

sql = "select _wstart, tbcol, tbname, 1, tgcol, count(tbcol) from m_in_mt0 partition by tbname interval(5m);"
tdSql.error(sql)

sql = "select _wstart, ts, tbname, 1, tgcol, count(tbcol) from m_in_mt0 partition by tbname interval(5m);"
tdSql.error(sql)
Comment on lines +1607 to +1619
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

There's an inconsistent use of trailing semicolons in the SQL queries within this block. For consistency with the rest of the file and general Python practice for single-statement strings, it's better to remove them.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -230,6 +230,7 @@ def test_state_window(self):
self.check_crash_for_state_window3()
self.check_crash_for_state_window4()
self.check_crash_for_state_window5()
self.test_state_window_start_with_null()

#tdSql.close()
tdLog.success(f"{__file__} successfully executed")
Expand All@@ -254,6 +255,7 @@ def test_state_window_start_with_null(self):

"""

tdLog.info("test state window start with null start")
tdSql.execute("drop database if exists testdb")
tdSql.execute("create database if not exists testdb keep 3650", show=True)
tdSql.execute("use testdb")
Expand DownExpand Up@@ -330,5 +332,28 @@ def test_state_window_start_with_null(self):
tdSql.checkData(3, 8, "2025-09-01 10:00:13.000")
tdSql.checkData(3, 9, "2025-09-01 10:00:13.000")
tdSql.checkData(3, 10, "b")

sql = "select _wstart, _wduration, _wend, s from ntb state_window(s, 2)"
tdSql.query(sql, show=True)
tdSql.checkRows(4)
tdSql.checkData(0, 0, "2025-09-01 10:00:00.000")
tdSql.checkData(0, 1, 4000)
tdSql.checkData(0, 2, "2025-09-01 10:00:04.000")
tdSql.checkData(0, 3, "a")
tdSql.checkData(1, 0, "2025-09-01 10:00:04.001")
tdSql.checkData(1, 1, 3999)
tdSql.checkData(1, 2, "2025-09-01 10:00:08.000")
tdSql.checkData(1, 3, "b")
tdSql.checkData(2, 0, "2025-09-01 10:00:08.001")
tdSql.checkData(2, 1, 1999)
tdSql.checkData(2, 2, "2025-09-01 10:00:10.000")
tdSql.checkData(2, 3, "a")
tdSql.checkData(3, 0, "2025-09-01 10:00:10.001")
tdSql.checkData(3, 1, 2999)
tdSql.checkData(3, 2, "2025-09-01 10:00:13.000")
tdSql.checkData(3, 3, "b")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

This line has trailing whitespace, which should be removed to maintain code style consistency.

Suggested change
tdSql.checkData(3,3,"b")
tdSql.checkData(3,3,"b")


sql = "select _wstart, _wduration, _wend, v from ntb state_window(s, 2)"
tdSql.error(sql, show=True)

event = threading.Event()
12 changes: 12 additions & 0 deletionstest/cases/13-TimeSeriesExt/05-EventWindow/test_event.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,3 +278,15 @@ def test_event(self):
)
tdSql.checkRows(4)
tdLog.info(f"======rows={tdSql.getRows()})")

sql = "select _wstart, tbname from st partition by tbname event_window start with a > 0 end with b = 2 slimit 2 limit 2;"
tdSql.query(sql)
tdSql.checkRows(4)

sql = "select _wstart, _wend, tbname, 'xx' from st partition by tbname event_window start with a > 0 end with b = 2 slimit 2 limit 2;"
Comment on lines +282 to +286
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

The SQL queries here use trailing semicolons, which is inconsistent with the general style in the test suite. Please remove them for consistency.

tdSql.query(sql)
tdSql.checkRows(4)
tdSql.checkData(0, 3, 'xx')

tdLog.info(f"======== test_event successfully executed")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

The file should end with a newline character. This is a common convention to prevent issues with file concatenation and some tools.

Suggested change

91 changes: 90 additions & 1 deletiontest/cases/13-TimeSeriesExt/06-SessionWindow/test_session.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,96 @@ def query(self):
tdSql.error(
f"select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0'"
)


sql = "select _wstart, _wend, 1, count(*) from dev_001 session(ts,1d)"
tdSql.query(sql)
tdSql.checkRows(4)
tdSql.checkData(0, 0, "2020-05-13 10:00:00.000")
tdSql.checkData(0, 1, "2020-05-14 13:00:00.001")
tdSql.checkData(0, 2, 1)
tdSql.checkData(0, 3, 13)
tdSql.checkData(1, 0, "2020-05-15 14:00:00.000")
tdSql.checkData(1, 1, "2020-05-15 14:00:00.000")
tdSql.checkData(1, 2, 1)
tdSql.checkData(2, 0, "2020-05-20 10:00:00.000")
tdSql.checkData(2, 1, "2020-05-20 10:00:00.000")
tdSql.checkData(2, 2, 1)
tdSql.checkData(3, 0, "2020-05-27 10:00:00.001")
tdSql.checkData(3, 1, "2020-05-27 10:00:00.001")
tdSql.checkData(3, 2, 1)


sql = "select _wstart, _wend, 1 from dev_001 session(ts,1d)"
tdSql.query(sql)
tdSql.checkRows(4)
tdSql.checkData(0, 0, "2020-05-13 10:00:00.000")
tdSql.checkData(0, 1, "2020-05-14 13:00:00.001")
tdSql.checkData(0, 2, 1)
tdSql.checkData(1, 0, "2020-05-15 14:00:00.000")
tdSql.checkData(1, 1, "2020-05-15 14:00:00.000")
tdSql.checkData(1, 2, 1)
tdSql.checkData(2, 0, "2020-05-20 10:00:00.000")
tdSql.checkData(2, 1, "2020-05-20 10:00:00.000")
tdSql.checkData(2, 2, 1)
tdSql.checkData(3, 0, "2020-05-27 10:00:00.001")
tdSql.checkData(3, 1, "2020-05-27 10:00:00.001")
tdSql.checkData(3, 2, 1)
Comment on lines +153 to +185
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

The test logic for queries with and withoutcount(*) is very similar, leading to significant code duplication. Consider refactoring this into a helper function to improve readability and maintainability. The function could take theselect clause as an argument and perform the common checks.


sql = "select _wstart, _wend, 1, ts from dev_001 session(ts,1d);"
tdSql.error(sql)

sql = "select _wstart, _wend, 1, dev from dev_001 session(ts,1d)"
tdSql.error(sql)

sql = "select _wstart, _wend, 1, tbname, count(*) from st partition by tbname session(ts,1d) order by tbname;"
tdSql.query(sql)
tdSql.checkRows(5)
tdSql.checkData(0, 0, "2020-05-13 10:00:00.000")
tdSql.checkData(0, 1, "2020-05-14 13:00:00.001")
tdSql.checkData(0, 2, 1)
tdSql.checkData(0, 3, "dev_001")
tdSql.checkData(1, 0, "2020-05-15 14:00:00.000")
tdSql.checkData(1, 1, "2020-05-15 14:00:00.000")
tdSql.checkData(1, 2, 1)
tdSql.checkData(1, 3, "dev_001")
tdSql.checkData(2, 0, "2020-05-20 10:00:00.000")
tdSql.checkData(2, 1, "2020-05-20 10:00:00.000")
tdSql.checkData(2, 2, 1)
tdSql.checkData(2, 3, "dev_001")
tdSql.checkData(3, 0, "2020-05-27 10:00:00.001")
tdSql.checkData(3, 1, "2020-05-27 10:00:00.001")
tdSql.checkData(3, 2, 1)
tdSql.checkData(3, 3, "dev_001")
tdSql.checkData(4, 0, "2020-05-13 10:00:00.000")
tdSql.checkData(4, 1, "2020-05-13 10:00:00.510")
tdSql.checkData(4, 2, 1)
tdSql.checkData(4, 3, "dev_002")


sql = "select _wstart, _wend, 1, tbname from st partition by tbname session(ts,1d) order by tbname;"
tdSql.query(sql)
tdSql.checkRows(5)
tdSql.checkData(0, 0, "2020-05-13 10:00:00.000")
tdSql.checkData(0, 1, "2020-05-14 13:00:00.001")
tdSql.checkData(0, 2, 1)
tdSql.checkData(0, 3, "dev_001")
tdSql.checkData(1, 0, "2020-05-15 14:00:00.000")
tdSql.checkData(1, 1, "2020-05-15 14:00:00.000")
tdSql.checkData(1, 2, 1)
tdSql.checkData(1, 3, "dev_001")
tdSql.checkData(2, 0, "2020-05-20 10:00:00.000")
tdSql.checkData(2, 1, "2020-05-20 10:00:00.000")
tdSql.checkData(2, 2, 1)
tdSql.checkData(2, 3, "dev_001")
tdSql.checkData(3, 0, "2020-05-27 10:00:00.001")
tdSql.checkData(3, 1, "2020-05-27 10:00:00.001")
tdSql.checkData(3, 2, 1)
tdSql.checkData(3, 3, "dev_001")
tdSql.checkData(4, 0, "2020-05-13 10:00:00.000")
tdSql.checkData(4, 1, "2020-05-13 10:00:00.510")
tdSql.checkData(4, 2, 1)
tdSql.checkData(4, 3, "dev_002")
Comment on lines +193 to +240
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

Similar to the previous section, these two test blocks for queries with and withoutcount(*) on a partitioned table are highly repetitive. A helper function could abstract the common setup and assertions, making the test code more concise and easier to maintain.


# print ====> select count(*) from dev_001 session(ts,1u)
# sql select _wstart, count(*) from dev_001 session(ts,1u)
# print rows: $rows
Expand Down
22 changes: 22 additions & 0 deletionstest/cases/13-TimeSeriesExt/07-CountWindow/test_count.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -641,4 +641,26 @@ def Count1(self):
f"select _wstart, count(*) c1, tbname from st partition by tbname count_window(2) slimit 2 limit 2;"
)
tdSql.checkRows(4)

sql = f"select _wstart, 1, ta, tb, tc, tbname from st partition by tbname count_window(2) slimit 2 limit 2;"
tdSql.query(sql)
tdSql.checkRows(4)

sql = f"select _wstart, 1, ta, tb, tc, tbname from t1 partition by tbname count_window(2) slimit 2 limit 2;"
tdSql.query(sql)
tdSql.checkRows(2)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

This line contains unnecessary whitespace. It should be removed to maintain a clean code style.

sql = f"select _wstart, 1, ta, tb, tc, tbname from t1 count_window(2) slimit 2 limit 2;"
tdSql.error(sql)
sql = f"select _wstart, 1, ta, tb, tc, count(*), tbname from t1 count_window(2) slimit 2 limit 2;"
tdSql.error(sql)

sql = f"select _wstart, 1 from t1 count_window(2);"
tdSql.query(sql)
tdSql.checkRows(3)

sql = f"select _wstart, 1, count(*) from t1 count_window(2);"
tdSql.query(sql)
Comment on lines +653 to +663
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

Some SQL queries in this block end with a semicolon, while others do not. For consistency, it's recommended to remove the trailing semicolons from all queries.

tdSql.checkRows(3)

tdLog.info(f"query_count0 end")
Loading

[8]ページ先頭

©2009-2025 Movatter.jp