Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5a0668da
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
未验证
提交
5a0668da
编写于
7月 20, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
7月 20, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15181 from taosdata/fix/TD-17511
fix(query): twa function handling null constant or all null column
上级
aa84a1bf
01385a4b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
80 addition
and
43 deletion
+80
-43
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+53
-16
tests/system-test/2-query/max_partition.py
tests/system-test/2-query/max_partition.py
+27
-27
未找到文件。
source/libs/function/src/builtinsimpl.c
浏览文件 @
5a0668da
...
@@ -165,6 +165,7 @@ typedef struct SElapsedInfo {
...
@@ -165,6 +165,7 @@ typedef struct SElapsedInfo {
typedef
struct
STwaInfo
{
typedef
struct
STwaInfo
{
double
dOutput
;
double
dOutput
;
bool
isNull
;
SPoint1
p
;
SPoint1
p
;
STimeWindow
win
;
STimeWindow
win
;
}
STwaInfo
;
}
STwaInfo
;
...
@@ -5181,6 +5182,7 @@ bool twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
...
@@ -5181,6 +5182,7 @@ bool twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
}
}
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
pInfo
->
isNull
=
false
;
pInfo
->
p
.
key
=
INT64_MIN
;
pInfo
->
p
.
key
=
INT64_MIN
;
pInfo
->
win
=
TSWINDOW_INITIALIZER
;
pInfo
->
win
=
TSWINDOW_INITIALIZER
;
return
true
;
return
true
;
...
@@ -5208,12 +5210,22 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5208,12 +5210,22 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
SPoint1
*
last
=
&
pInfo
->
p
;
SPoint1
*
last
=
&
pInfo
->
p
;
int32_t
numOfElems
=
0
;
int32_t
numOfElems
=
0
;
if
(
IS_NULL_TYPE
(
pInputCol
->
info
.
type
))
{
pInfo
->
isNull
=
true
;
goto
_twa_over
;
}
int32_t
i
=
pInput
->
startRowIndex
;
int32_t
i
=
pInput
->
startRowIndex
;
if
(
pCtx
->
start
.
key
!=
INT64_MIN
)
{
if
(
pCtx
->
start
.
key
!=
INT64_MIN
)
{
ASSERT
((
pCtx
->
start
.
key
<
tsList
[
i
]
&&
pCtx
->
order
==
TSDB_ORDER_ASC
)
||
ASSERT
((
pCtx
->
start
.
key
<
tsList
[
i
]
&&
pCtx
->
order
==
TSDB_ORDER_ASC
)
||
(
pCtx
->
start
.
key
>
tsList
[
i
]
&&
pCtx
->
order
==
TSDB_ORDER_DESC
));
(
pCtx
->
start
.
key
>
tsList
[
i
]
&&
pCtx
->
order
==
TSDB_ORDER_DESC
));
ASSERT
(
last
->
key
==
INT64_MIN
);
ASSERT
(
last
->
key
==
INT64_MIN
);
for
(;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
}
last
->
key
=
tsList
[
i
];
last
->
key
=
tsList
[
i
];
GET_TYPED_DATA
(
last
->
val
,
double
,
pInputCol
->
info
.
type
,
colDataGetData
(
pInputCol
,
i
));
GET_TYPED_DATA
(
last
->
val
,
double
,
pInputCol
->
info
.
type
,
colDataGetData
(
pInputCol
,
i
));
...
@@ -5222,13 +5234,23 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5222,13 +5234,23 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
pInfo
->
win
.
skey
=
pCtx
->
start
.
key
;
pInfo
->
win
.
skey
=
pCtx
->
start
.
key
;
numOfElems
++
;
numOfElems
++
;
i
+=
1
;
i
+=
1
;
break
;
}
}
else
if
(
pInfo
->
p
.
key
==
INT64_MIN
)
{
}
else
if
(
pInfo
->
p
.
key
==
INT64_MIN
)
{
for
(;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
}
last
->
key
=
tsList
[
i
];
last
->
key
=
tsList
[
i
];
GET_TYPED_DATA
(
last
->
val
,
double
,
pInputCol
->
info
.
type
,
colDataGetData
(
pInputCol
,
i
));
GET_TYPED_DATA
(
last
->
val
,
double
,
pInputCol
->
info
.
type
,
colDataGetData
(
pInputCol
,
i
));
pInfo
->
win
.
skey
=
last
->
key
;
pInfo
->
win
.
skey
=
last
->
key
;
numOfElems
++
;
numOfElems
++
;
i
+=
1
;
i
+=
1
;
break
;
}
}
}
SPoint1
st
=
{
0
};
SPoint1
st
=
{
0
};
...
@@ -5241,6 +5263,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5241,6 +5263,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5255,6 +5278,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5255,6 +5278,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5268,6 +5292,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5268,6 +5292,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5281,6 +5306,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5281,6 +5306,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5294,6 +5320,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5294,6 +5320,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5307,6 +5334,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5307,6 +5334,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5320,6 +5348,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5320,6 +5348,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5333,6 +5362,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5333,6 +5362,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5346,6 +5376,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5346,6 +5376,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5359,6 +5390,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5359,6 +5390,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
numOfElems
++
;
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
INIT_INTP_POINT
(
st
,
tsList
[
i
],
val
[
i
]);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
pInfo
->
dOutput
+=
twa_get_area
(
pInfo
->
p
,
st
);
...
@@ -5379,7 +5411,12 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
...
@@ -5379,7 +5411,12 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
pInfo
->
win
.
ekey
=
pInfo
->
p
.
key
;
pInfo
->
win
.
ekey
=
pInfo
->
p
.
key
;
SET_VAL
(
pResInfo
,
numOfElems
,
1
);
_twa_over:
if
(
numOfElems
==
0
)
{
pInfo
->
isNull
=
true
;
}
SET_VAL
(
pResInfo
,
1
,
1
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -5400,8 +5437,8 @@ int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
...
@@ -5400,8 +5437,8 @@ int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
(
STwaInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
STwaInfo
*
pInfo
=
(
STwaInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
if
(
p
ResInfo
->
numOfRes
==
0
)
{
if
(
p
Info
->
isNull
==
true
)
{
pResInfo
->
isNullRes
=
1
;
pResInfo
->
numOfRes
=
0
;
}
else
{
}
else
{
if
(
pInfo
->
win
.
ekey
==
pInfo
->
win
.
skey
)
{
if
(
pInfo
->
win
.
ekey
==
pInfo
->
win
.
skey
)
{
pInfo
->
dOutput
=
pInfo
->
p
.
val
;
pInfo
->
dOutput
=
pInfo
->
p
.
val
;
...
...
tests/system-test/2-query/max_partition.py
浏览文件 @
5a0668da
...
@@ -184,7 +184,7 @@ class TDTestCase:
...
@@ -184,7 +184,7 @@ class TDTestCase:
tdSql
.
query
(
"select c1 , twa(c1) from stb partition by c1 order by c1"
)
tdSql
.
query
(
"select c1 , twa(c1) from stb partition by c1 order by c1"
)
tdSql
.
checkRows
(
11
)
tdSql
.
checkRows
(
11
)
tdSql
.
checkData
(
0
,
1
,
0.000000000
)
tdSql
.
checkData
(
0
,
1
,
None
)
tdSql
.
query
(
"select c1 , irate(c1) from stb partition by c1 order by c1"
)
tdSql
.
query
(
"select c1 , irate(c1) from stb partition by c1 order by c1"
)
tdSql
.
checkRows
(
11
)
tdSql
.
checkRows
(
11
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录