From bea434623287ebaa7d3898675277e2f7ca3ac58c Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 8 Aug 2023 16:05:21 +0800 Subject: [PATCH 1/7] enh: remove timeline dependence of certain functions --- source/libs/function/src/builtins.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 6eb2be34b3..be94352f29 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -2348,7 +2348,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "leastsquares", .type = FUNCTION_TYPE_LEASTSQUARES, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_FORBID_SYSTABLE_FUNC, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_FORBID_SYSTABLE_FUNC, .translateFunc = translateLeastSQR, .getEnvFunc = getLeastSQRFuncEnv, .initFunc = leastSQRFunctionSetup, @@ -2914,8 +2914,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "tail", .type = FUNCTION_TYPE_TAIL, - .classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | - FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC, + .classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC, .translateFunc = translateTail, .getEnvFunc = getTailFuncEnv, .initFunc = tailFunctionSetup, @@ -2926,8 +2925,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "unique", .type = FUNCTION_TYPE_UNIQUE, - .classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | - FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC, + .classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC, .translateFunc = translateUnique, .getEnvFunc = getUniqueFuncEnv, .initFunc = uniqueFunctionSetup, From 2ed5ee835e8c6f10e782fe296f92c60ffa658fae Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 8 Aug 2023 16:08:59 +0800 Subject: [PATCH 2/7] fix docs --- docs/en/12-taos-sql/10-function.md | 2 +- docs/zh/12-taos-sql/10-function.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/12-taos-sql/10-function.md b/docs/en/12-taos-sql/10-function.md index afc1581c22..f3eb9516b6 100644 --- a/docs/en/12-taos-sql/10-function.md +++ b/docs/en/12-taos-sql/10-function.md @@ -698,7 +698,7 @@ ELAPSED(ts_primary_key [, time_unit]) LEASTSQUARES(expr, start_val, step_val) ``` -**Description**: The linear regression function of the specified column and the timestamp column (primary key), `start_val` is the initial value and `step_val` is the step value. +**Description**: The linear regression function of a specified column, `start_val` is the initial value and `step_val` is the step value. **Return value type**: A string in the format of "(slope, intercept)" diff --git a/docs/zh/12-taos-sql/10-function.md b/docs/zh/12-taos-sql/10-function.md index fc0cfbe330..4a51358fa0 100644 --- a/docs/zh/12-taos-sql/10-function.md +++ b/docs/zh/12-taos-sql/10-function.md @@ -700,7 +700,7 @@ ELAPSED(ts_primary_key [, time_unit]) LEASTSQUARES(expr, start_val, step_val) ``` -**功能说明**:统计表中某列的值是主键(时间戳)的拟合直线方程。start_val 是自变量初始值,step_val 是自变量的步长值。 +**功能说明**:统计表中某列的值的拟合直线方程。start_val 是自变量初始值,step_val 是自变量的步长值。 **返回数据类型**:字符串表达式(斜率, 截距)。 From 8b84e0544c44bb8f2504e79b26f1dbcb63b4e7c5 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 9 Aug 2023 11:40:23 +0800 Subject: [PATCH 3/7] add test cases for leastsquares --- tests/system-test/2-query/leastsquares.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/system-test/2-query/leastsquares.py b/tests/system-test/2-query/leastsquares.py index 1718802a82..f433e702ec 100644 --- a/tests/system-test/2-query/leastsquares.py +++ b/tests/system-test/2-query/leastsquares.py @@ -219,7 +219,7 @@ class TDTestCase: tdSql.checkRows(1) res = tdSql.getData(0, 0) if res is None: - tdLog.exit("result is not correct") + tdLog.exit("result is not correct") def __test_current(self): # tdSql.query("explain select c1 from {dbname}.ct1") @@ -228,6 +228,11 @@ class TDTestCase: # tdSql.query("explain select count(c3) from {dbname}.ct4 group by c7 having count(c3) > 0") # tdSql.query("explain select ct2.c3 from {dbname}.ct4 join ct2 on ct4.ts=ct2.ts") # tdSql.query("explain select c1 from stb1 where c1 is not null and c1 in (0, 1, 2) or c1 between 2 and 100 ") + # + tdSql.query("select leastsquares(c1, 1, 1) from (select c1 from nt1 group by c1)") + tdSql.query("select leastsquares(c1, 1, 1) from (select c1 from nt1 partition by c1)") + tdSql.query("select leastsquares(c1, 1, 1) from (select c1 from nt1 order by c1)") + tdSql.query("select leastsquares(c1, 1, 1) from (select c1 from nt1 union select c1 from nt1)") self.leastsquares_check() From 6ab16e89d41115c7b186b10f0ed29afff04b5beb Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 9 Aug 2023 14:27:41 +0800 Subject: [PATCH 4/7] add tail, unique cases --- tests/system-test/2-query/tail.py | 12 ++++++++++++ tests/system-test/2-query/unique.py | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/tests/system-test/2-query/tail.py b/tests/system-test/2-query/tail.py index 43321810d0..353aa36043 100644 --- a/tests/system-test/2-query/tail.py +++ b/tests/system-test/2-query/tail.py @@ -412,6 +412,18 @@ class TDTestCase: tdSql.checkData(0,0,4) tdSql.checkData(1,0,1) + tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from ct1 group by c2);") + tdSql.checkRows(1) + + tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from ct1 partition by c2);") + tdSql.checkRows(1) + + tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from ct1 order by c2);") + tdSql.checkRows(1) + + tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from ct1 union select _rowts, first(c2) as a from ct1);") + tdSql.checkRows(1) + def check_boundary_values(self, dbname="bound_test"): tdSql.execute(f"drop database if exists {dbname}") diff --git a/tests/system-test/2-query/unique.py b/tests/system-test/2-query/unique.py index 9b5da50e1f..bfd65c1fe2 100644 --- a/tests/system-test/2-query/unique.py +++ b/tests/system-test/2-query/unique.py @@ -438,6 +438,15 @@ class TDTestCase: tdSql.checkData(0,0,4) tdSql.checkData(1,0,1) + tdSql.query(f"select unique(c1) v from (select _rowts , c1 from {dbname}.ct1 partition by c2)") + tdSql.checkRows(10) + + tdSql.query(f"select unique(c1) v from (select _rowts , c1 from {dbname}.ct1 order by c2)") + tdSql.checkRows(10) + + tdSql.query(f"select unique(c1) v from (select _rowts , c1 from {dbname}.ct1 union all select _rowts , c1 from {dbname}.ct1)") + tdSql.checkRows(10) + # TD-19911 tdSql.error("select unique(mode(12)) from (select _rowts , t1 , tbname from db.stb1 );") tdSql.error("select unique(mode(t1,1)) from (select _rowts , t1 , tbname from db.stb1 );") From 70e4b4f44eb3b6abbb40d43e59fe24dab4b7b0b6 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 9 Aug 2023 14:30:34 +0800 Subject: [PATCH 5/7] remove unique need of primary ts --- source/libs/function/src/builtins.c | 2 +- tests/system-test/2-query/unique.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index be94352f29..51d51db6e8 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -2925,7 +2925,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "unique", .type = FUNCTION_TYPE_UNIQUE, - .classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC, + .classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, .translateFunc = translateUnique, .getEnvFunc = getUniqueFuncEnv, .initFunc = uniqueFunctionSetup, diff --git a/tests/system-test/2-query/unique.py b/tests/system-test/2-query/unique.py index bfd65c1fe2..a3238ce8d1 100644 --- a/tests/system-test/2-query/unique.py +++ b/tests/system-test/2-query/unique.py @@ -438,13 +438,13 @@ class TDTestCase: tdSql.checkData(0,0,4) tdSql.checkData(1,0,1) - tdSql.query(f"select unique(c1) v from (select _rowts , c1 from {dbname}.ct1 partition by c2)") + tdSql.query(f"select unique(c1) v from (select c1 from {dbname}.ct1 partition by c2)") tdSql.checkRows(10) - tdSql.query(f"select unique(c1) v from (select _rowts , c1 from {dbname}.ct1 order by c2)") + tdSql.query(f"select unique(c1) v from (select c1 from {dbname}.ct1 order by c2)") tdSql.checkRows(10) - tdSql.query(f"select unique(c1) v from (select _rowts , c1 from {dbname}.ct1 union all select _rowts , c1 from {dbname}.ct1)") + tdSql.query(f"select unique(c1) v from (select c1 from {dbname}.ct1 union all select c1 from {dbname}.ct1)") tdSql.checkRows(10) # TD-19911 From 11823580c7fc149268f73bb4bbf16bcbce563fda Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 9 Aug 2023 17:13:31 +0800 Subject: [PATCH 6/7] fix test cases --- source/libs/function/src/builtins.c | 2 +- tests/system-test/2-query/unique.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 51d51db6e8..be94352f29 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -2925,7 +2925,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "unique", .type = FUNCTION_TYPE_UNIQUE, - .classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, + .classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC, .translateFunc = translateUnique, .getEnvFunc = getUniqueFuncEnv, .initFunc = uniqueFunctionSetup, diff --git a/tests/system-test/2-query/unique.py b/tests/system-test/2-query/unique.py index a3238ce8d1..b3053817d3 100644 --- a/tests/system-test/2-query/unique.py +++ b/tests/system-test/2-query/unique.py @@ -438,13 +438,13 @@ class TDTestCase: tdSql.checkData(0,0,4) tdSql.checkData(1,0,1) - tdSql.query(f"select unique(c1) v from (select c1 from {dbname}.ct1 partition by c2)") + tdSql.query(f"select unique(c1) v from (select _rowts, c1 from {dbname}.ct1 partition by c2)") tdSql.checkRows(10) - tdSql.query(f"select unique(c1) v from (select c1 from {dbname}.ct1 order by c2)") + tdSql.query(f"select unique(c1) v from (select _rowts, c1 from {dbname}.ct1 order by c2)") tdSql.checkRows(10) - tdSql.query(f"select unique(c1) v from (select c1 from {dbname}.ct1 union all select c1 from {dbname}.ct1)") + tdSql.query(f"select unique(c1) v from (select _rowts, c1 from {dbname}.ct1 union all select _rowts, c1 from {dbname}.ct1)") tdSql.checkRows(10) # TD-19911 From b17f4a9c586fe65daffdc8eaee8f8e280ff98b3d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 10 Aug 2023 11:05:18 +0800 Subject: [PATCH 7/7] add test cases --- tests/system-test/2-query/leastsquares.py | 10 +++++----- tests/system-test/2-query/tail.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/system-test/2-query/leastsquares.py b/tests/system-test/2-query/leastsquares.py index f433e702ec..3dfd1f6aca 100644 --- a/tests/system-test/2-query/leastsquares.py +++ b/tests/system-test/2-query/leastsquares.py @@ -221,7 +221,7 @@ class TDTestCase: if res is None: tdLog.exit("result is not correct") - def __test_current(self): + def __test_current(self, dbname=DBNAME): # tdSql.query("explain select c1 from {dbname}.ct1") # tdSql.query("explain select 1 from {dbname}.ct2") # tdSql.query("explain select cast(ceil(c6) as bigint) from {dbname}.ct4 group by c6") @@ -229,10 +229,10 @@ class TDTestCase: # tdSql.query("explain select ct2.c3 from {dbname}.ct4 join ct2 on ct4.ts=ct2.ts") # tdSql.query("explain select c1 from stb1 where c1 is not null and c1 in (0, 1, 2) or c1 between 2 and 100 ") # - tdSql.query("select leastsquares(c1, 1, 1) from (select c1 from nt1 group by c1)") - tdSql.query("select leastsquares(c1, 1, 1) from (select c1 from nt1 partition by c1)") - tdSql.query("select leastsquares(c1, 1, 1) from (select c1 from nt1 order by c1)") - tdSql.query("select leastsquares(c1, 1, 1) from (select c1 from nt1 union select c1 from nt1)") + tdSql.query(f"select leastsquares(c1, 1, 1) from (select c1 from {dbname}.nt1 group by c1)") + tdSql.query(f"select leastsquares(c1, 1, 1) from (select c1 from {dbname}.nt1 partition by c1)") + tdSql.query(f"select leastsquares(c1, 1, 1) from (select c1 from {dbname}.nt1 order by c1)") + tdSql.query(f"select leastsquares(c1, 1, 1) from (select c1 from {dbname}.nt1 union select c1 from {dbname}.nt1)") self.leastsquares_check() diff --git a/tests/system-test/2-query/tail.py b/tests/system-test/2-query/tail.py index 353aa36043..99791db3df 100644 --- a/tests/system-test/2-query/tail.py +++ b/tests/system-test/2-query/tail.py @@ -412,16 +412,16 @@ class TDTestCase: tdSql.checkData(0,0,4) tdSql.checkData(1,0,1) - tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from ct1 group by c2);") + tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from {dbname}.ct1 group by c2);") tdSql.checkRows(1) - tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from ct1 partition by c2);") + tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from {dbname}.ct1 partition by c2);") tdSql.checkRows(1) - tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from ct1 order by c2);") + tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from {dbname}.ct1 order by c2);") tdSql.checkRows(1) - tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from ct1 union select _rowts, first(c2) as a from ct1);") + tdSql.query(f"select tail(a, 1) from (select _rowts, first(c2) as a from {dbname}.ct1 union select _rowts, first(c2) as a from {dbname}.ct1);") tdSql.checkRows(1) def check_boundary_values(self, dbname="bound_test"):