Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
56ca1ac2
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
56ca1ac2
编写于
8月 01, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
8月 01, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15643 from taosdata/fix/TD-18040
enh(query): add selectivity support for indefinite rows functions
上级
a01ebbbf
0b3ebaeb
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
375 addition
and
291 deletion
+375
-291
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+1
-1
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+4
-4
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+30
-1
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+257
-257
tests/system-test/2-query/csum.py
tests/system-test/2-query/csum.py
+21
-7
tests/system-test/2-query/function_stateduration.py
tests/system-test/2-query/function_stateduration.py
+13
-9
tests/system-test/2-query/statecount.py
tests/system-test/2-query/statecount.py
+45
-8
tests/system-test/fulltest.sh
tests/system-test/fulltest.sh
+4
-4
未找到文件。
source/libs/executor/src/executorimpl.c
浏览文件 @
56ca1ac2
...
...
@@ -672,7 +672,7 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc
numOfRows
=
pfCtx
->
fpSet
.
process
(
pfCtx
);
}
else
if
(
fmIsAggFunc
(
pfCtx
->
functionId
))
{
//
diff/derivative selective value should be set dur
ing function execution
//
selective value output should be set during correspond
ing function execution
if
(
fmIsSelectValueFunc
(
pfCtx
->
functionId
))
{
continue
;
}
...
...
source/libs/function/src/builtins.c
浏览文件 @
56ca1ac2
...
...
@@ -2465,7 +2465,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"statecount"
,
.
type
=
FUNCTION_TYPE_STATE_COUNT
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_
SELECT_FUNC
|
FUNC_MGT_
TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
,
.
translateFunc
=
translateStateCount
,
.
getEnvFunc
=
getStateFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -2476,7 +2476,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"stateduration"
,
.
type
=
FUNCTION_TYPE_STATE_DURATION
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_
SELECT_FUNC
|
FUNC_MGT_
TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
,
.
translateFunc
=
translateStateDuration
,
.
getEnvFunc
=
getStateFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -2487,7 +2487,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"csum"
,
.
type
=
FUNCTION_TYPE_CSUM
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
|
FUNC_MGT_CUMULATIVE_FUNC
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_
SELECT_FUNC
|
FUNC_MGT_
TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
|
FUNC_MGT_CUMULATIVE_FUNC
,
.
translateFunc
=
translateCsum
,
.
getEnvFunc
=
getCsumFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -2499,7 +2499,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"mavg"
,
.
type
=
FUNCTION_TYPE_MAVG
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_
SELECT_FUNC
|
FUNC_MGT_
TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
,
.
translateFunc
=
translateMavg
,
.
getEnvFunc
=
getMavgFuncEnv
,
.
initFunc
=
mavgFunctionSetup
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
56ca1ac2
...
...
@@ -4651,10 +4651,15 @@ int32_t stateCountFunction(SqlFunctionCtx* pCtx) {
numOfElems
++
;
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
colDataAppendNULL
(
pOutput
,
i
);
// handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
appendSelectivityValue
(
pCtx
,
i
,
i
);
}
continue
;
}
bool
ret
=
checkStateOp
(
op
,
pInputCol
,
i
,
pCtx
->
param
[
2
].
param
);
bool
ret
=
checkStateOp
(
op
,
pInputCol
,
i
,
pCtx
->
param
[
2
].
param
);
int64_t
output
=
-
1
;
if
(
ret
)
{
output
=
++
pInfo
->
count
;
...
...
@@ -4662,6 +4667,11 @@ int32_t stateCountFunction(SqlFunctionCtx* pCtx) {
pInfo
->
count
=
0
;
}
colDataAppend
(
pOutput
,
i
,
(
char
*
)
&
output
,
false
);
// handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
appendSelectivityValue
(
pCtx
,
i
,
i
);
}
}
return
numOfElems
;
...
...
@@ -4694,6 +4704,10 @@ int32_t stateDurationFunction(SqlFunctionCtx* pCtx) {
numOfElems
++
;
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
colDataAppendNULL
(
pOutput
,
i
);
// handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
appendSelectivityValue
(
pCtx
,
i
,
i
);
}
continue
;
}
...
...
@@ -4710,6 +4724,11 @@ int32_t stateDurationFunction(SqlFunctionCtx* pCtx) {
pInfo
->
durationStart
=
0
;
}
colDataAppend
(
pOutput
,
i
,
(
char
*
)
&
output
,
false
);
// handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
appendSelectivityValue
(
pCtx
,
i
,
i
);
}
}
return
numOfElems
;
...
...
@@ -4762,6 +4781,11 @@ int32_t csumFunction(SqlFunctionCtx* pCtx) {
}
}
// handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
appendSelectivityValue
(
pCtx
,
i
,
pos
);
}
numOfElems
++
;
}
...
...
@@ -4834,6 +4858,11 @@ int32_t mavgFunction(SqlFunctionCtx* pCtx) {
colDataAppend
(
pOutput
,
pos
,
(
char
*
)
&
result
,
false
);
}
// handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
appendSelectivityValue
(
pCtx
,
i
,
pos
);
}
numOfElems
++
;
}
...
...
source/libs/scalar/src/filter.c
浏览文件 @
56ca1ac2
此差异已折叠。
点击以展开。
tests/system-test/2-query/csum.py
浏览文件 @
56ca1ac2
...
...
@@ -279,14 +279,14 @@ class TDTestCase:
tdSql
.
error
(
self
.
csum_query_form
(
alias
=
", diff(c1)"
))
# mix with calculation function 2
# tdSql.error(self.csum_query_form(alias=" + 2")) # mix with arithmetic 1
tdSql
.
error
(
self
.
csum_query_form
(
alias
=
" + avg(c1)"
))
# mix with arithmetic 2
tdSql
.
error
(
self
.
csum_query_form
(
alias
=
", c2"
))
# mix with other 1
#
tdSql.error(self.csum_query_form(alias=", c2")) # mix with other 1
# tdSql.error(self.csum_query_form(table_expr="stb1")) # select stb directly
stb_join
=
{
"col"
:
"stb1.c1"
,
"table_expr"
:
"stb1, stb2"
,
"condition"
:
"where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts"
}
tdSql
.
error
(
self
.
csum_query_form
(
**
stb_join
))
# stb join
#
stb_join = {
#
"col": "stb1.c1",
#
"table_expr": "stb1, stb2",
#
"condition": "where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts"
#
}
#
tdSql.error(self.csum_query_form(**stb_join)) # stb join
interval_sql
=
{
"condition"
:
"where ts>0 and ts < now interval(1h) fill(next)"
}
...
...
@@ -421,6 +421,19 @@ class TDTestCase:
tdSql
.
query
(
"select csum(abs(c1))+2 from db.t1 "
)
tdSql
.
checkRows
(
4
)
# support selectivity
tdSql
.
query
(
"select ts, c1, csum(1) from db.t1"
)
tdSql
.
checkRows
(
7
)
tdSql
.
query
(
"select csum(1), ts, c1 from db.t1"
)
tdSql
.
checkRows
(
7
)
tdSql
.
query
(
"select ts, c1, c2, c3, csum(1), ts, c4, c5, c6 from db.t1"
)
tdSql
.
checkRows
(
7
)
tdSql
.
query
(
"select ts, c1, csum(1), c4, c5, csum(1), c6 from db.t1"
)
tdSql
.
checkRows
(
7
)
def
csum_support_stable
(
self
):
tdSql
.
query
(
" select csum(1) from db.stb1 "
)
tdSql
.
checkRows
(
70
)
...
...
@@ -474,6 +487,7 @@ class TDTestCase:
# tdSql.checkRows(4)
def
run
(
self
):
import
traceback
try
:
...
...
tests/system-test/2-query/function_stateduration.py
浏览文件 @
56ca1ac2
...
...
@@ -104,8 +104,6 @@ class TDTestCase:
"select stateduration(c1 ,'GT',1,1s) , min(c1) from t1"
,
"select stateduration(c1 ,'GT',1,1s) , spread(c1) from t1"
,
"select stateduration(c1 ,'GT',1,1s) , diff(c1) from t1"
,
"select stateduration(c1 ,'GT',1,1s) , abs(c1) from t1"
,
"select stateduration(c1 ,'GT',1,1s) , c1 from t1"
,
]
for
error_sql
in
error_sql_lists
:
tdSql
.
error
(
error_sql
)
...
...
@@ -226,18 +224,24 @@ class TDTestCase:
tdSql
.
query
(
"select stateduration(c6,'GT',1,1s) from ct4"
)
tdSql
.
checkRows
(
12
)
tdSql
.
error
(
"select stateduration(c6,'GT',1,1s),tbname from ct1"
)
tdSql
.
error
(
"select stateduration(c6,'GT',1,1s),t1 from ct1"
)
tdSql
.
query
(
"select stateduration(c6,'GT',1,1s),tbname from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select stateduration(c6,'GT',1,1s),t1 from ct1"
)
tdSql
.
checkRows
(
13
)
# unique with common col
tdSql
.
error
(
"select stateduration(c6,'GT',1,1s) ,ts from ct1"
)
tdSql
.
error
(
"select stateduration(c6,'GT',1,1s) ,c1 from ct1"
)
tdSql
.
query
(
"select stateduration(c6,'GT',1,1s) ,ts from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select stateduration(c6,'GT',1,1s) ,c1 from ct1"
)
tdSql
.
checkRows
(
13
)
# unique with scalar function
tdSql
.
error
(
"select stateduration(c6,'GT',1,1s) ,abs(c1) from ct1"
)
tdSql
.
error
(
"select stateduration(c6,'GT',1,1s) , unique(c2) from ct1"
)
tdSql
.
error
(
"select stateduration(c6,'GT',1,1s) , abs(c2)+2 from ct1"
)
tdSql
.
query
(
"select stateduration(c6,'GT',1,1s) , abs(c1) from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select stateduration(c6,'GT',1,1s) , abs(c2)+2 from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
error
(
"select stateduration(c6,'GT',1,1s) , unique(c2) from ct1"
)
# unique with aggregate function
tdSql
.
error
(
"select stateduration(c6,'GT',1,1s) ,sum(c1) from ct1"
)
...
...
tests/system-test/2-query/statecount.py
浏览文件 @
56ca1ac2
...
...
@@ -105,8 +105,6 @@ class TDTestCase:
"select statecount(c1 ,'GT',1) , min(c1) from t1"
,
"select statecount(c1 ,'GT',1) , spread(c1) from t1"
,
"select statecount(c1 ,'GT',1) , diff(c1) from t1"
,
"select statecount(c1 ,'GT',1) , abs(c1) from t1"
,
"select statecount(c1 ,'GT',1) , c1 from t1"
,
]
for
error_sql
in
error_sql_lists
:
tdSql
.
error
(
error_sql
)
...
...
@@ -227,17 +225,56 @@ class TDTestCase:
tdSql
.
query
(
"select statecount(c6,'GT',1) from ct4"
)
tdSql
.
checkRows
(
12
)
tdSql
.
error
(
"select statecount(c6,'GT',1),tbname from ct1"
)
tdSql
.
error
(
"select statecount(c6,'GT',1),t1 from ct1"
)
tdSql
.
query
(
"select statecount(c6,'GT',1),tbname from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select statecount(c6,'GT',1),t1 from ct1"
)
tdSql
.
checkRows
(
13
)
# unique with common col
tdSql
.
error
(
"select statecount(c6,'GT',1) ,ts from ct1"
)
tdSql
.
error
(
"select statecount(c6,'GT',1) ,c1 from ct1"
)
tdSql
.
query
(
"select statecount(c6,'GT',1) ,ts from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select ts, statecount(c6,'GT',1) from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select statecount(c6,'GT',1) ,c1 from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select c1, statecount(c6,'GT',1) from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select ts, c1, c2, c3, statecount(c6,'GT',1) from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select statecount(c6,'GT',1), ts, c1, c2, c3 from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select ts, c1, c2, c3, statecount(c6,'GT',1), ts, c4, c5, c6 from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select stateduration(c6,'GT',1) ,ts from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select ts, stateduration(c6,'GT',1) from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select stateduration(c6,'GT',1) ,c1 from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select c1, stateduration(c6,'GT',1) from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select ts, c1, c2, c3, stateduration(c6,'GT',1) from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select stateduration(c6,'GT',1), ts, c1, c2, c3 from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select ts, c1, c2, c3, stateduration(c6,'GT',1), ts, c4, c5, c6 from ct1"
)
tdSql
.
checkRows
(
13
)
# unique with scalar function
tdSql
.
error
(
"select statecount(c6,'GT',1) ,abs(c1) from ct1"
)
tdSql
.
query
(
"select statecount(c6,'GT',1) , abs(c1) from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select statecount(c6,'GT',1) , abs(c2)+2 from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
error
(
"select statecount(c6,'GT',1) , unique(c2) from ct1"
)
tdSql
.
error
(
"select statecount(c6,'GT',1) , abs(c2)+2 from ct1"
)
tdSql
.
query
(
"select stateduration(c6,'GT',1) , abs(c1) from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select stateduration(c6,'GT',1) , abs(c2)+2 from ct1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
error
(
"select stateduration(c6,'GT',1) , unique(c2) from ct1"
)
# unique with aggregate function
...
...
tests/system-test/fulltest.sh
浏览文件 @
56ca1ac2
...
...
@@ -147,7 +147,7 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py
python3 ./test.py
-f
2-query/elapsed.py
python3 ./test.py
-f
2-query/csum.py
python3 ./test.py
-f
2-query/mavg.py
#
python3 ./test.py -f 2-query/mavg.py
python3 ./test.py
-f
2-query/sample.py
python3 ./test.py
-f
2-query/function_diff.py
python3 ./test.py
-f
2-query/unique.py
...
...
@@ -341,7 +341,7 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py -Q 2
python3 ./test.py
-f
2-query/avg.py
-Q
2
# python3 ./test.py -f 2-query/elapsed.py -Q 2
python3 ./test.py
-f
2-query/csum.py
-Q
2
python3 ./test.py
-f
2-query/mavg.py
-Q
2
#
python3 ./test.py -f 2-query/mavg.py -Q 2
python3 ./test.py
-f
2-query/sample.py
-Q
2
python3 ./test.py
-f
2-query/function_diff.py
-Q
2
python3 ./test.py
-f
2-query/unique.py
-Q
2
...
...
@@ -428,7 +428,7 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py -Q 3
# python3 ./test.py -f 2-query/avg.py -Q 3
# python3 ./test.py -f 2-query/elapsed.py -Q 3
python3 ./test.py
-f
2-query/csum.py
-Q
3
python3 ./test.py
-f
2-query/mavg.py
-Q
3
#
python3 ./test.py -f 2-query/mavg.py -Q 3
python3 ./test.py
-f
2-query/sample.py
-Q
3
python3 ./test.py
-f
2-query/function_diff.py
-Q
3
python3 ./test.py
-f
2-query/unique.py
-Q
3
...
...
@@ -452,4 +452,4 @@ python3 ./test.py -f 2-query/count_partition.py -Q 3
python3 ./test.py
-f
2-query/max_partition.py
-Q
3
python3 ./test.py
-f
2-query/last_row.py
-Q
3
python3 ./test.py
-f
2-query/tsbsQuery.py
-Q
3
python3 ./test.py
-f
2-query/sml.py
-Q
3
\ No newline at end of file
python3 ./test.py
-f
2-query/sml.py
-Q
3
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录