Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1fecbd25
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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,发现更多精彩内容 >>
未验证
提交
1fecbd25
编写于
5月 18, 2022
作者:
S
shenglian-zhou
提交者:
GitHub
5月 18, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12657 from taosdata/feature/udf
fix: improve udf function misuse stability
上级
9f599c23
36dcc70f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
26 deletion
+37
-26
source/libs/executor/src/executorMain.c
source/libs/executor/src/executorMain.c
+1
-0
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+36
-26
未找到文件。
source/libs/executor/src/executorMain.c
浏览文件 @
1fecbd25
...
...
@@ -133,6 +133,7 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
publishQueryAbortEvent
(
pTaskInfo
,
ret
);
pTaskInfo
->
code
=
ret
;
cleanUpUdfs
();
qDebug
(
"%s task abort due to error/cancel occurs, code:%s"
,
GET_TASKID
(
pTaskInfo
),
tstrerror
(
pTaskInfo
->
code
));
return
pTaskInfo
->
code
;
...
...
source/libs/function/src/tudf.c
浏览文件 @
1fecbd25
...
...
@@ -1364,9 +1364,12 @@ void releaseUdfFuncHandle(char* udfName) {
SUdfcFuncStub
key
=
{
0
};
strcpy
(
key
.
udfName
,
udfName
);
SUdfcFuncStub
*
foundStub
=
taosArraySearch
(
gUdfdProxy
.
udfStubs
,
&
key
,
compareUdfcFuncSub
,
TD_EQ
);
ASSERT
(
foundStub
);
--
foundStub
->
refCount
;
ASSERT
(
foundStub
->
refCount
>=
0
);
if
(
!
foundStub
)
{
return
;
}
if
(
foundStub
->
refCount
>
0
)
{
--
foundStub
->
refCount
;
}
uv_mutex_unlock
(
&
gUdfdProxy
.
udfStubsMutex
);
}
...
...
@@ -1377,7 +1380,7 @@ int32_t cleanUpUdfs() {
while
(
i
<
taosArrayGetSize
(
gUdfdProxy
.
udfStubs
))
{
SUdfcFuncStub
*
stub
=
taosArrayGet
(
gUdfdProxy
.
udfStubs
,
i
);
if
(
stub
->
refCount
==
0
)
{
fnInfo
(
"tear down udf. udf name: %s, handle: %p
"
,
stub
->
udfName
,
stub
->
handle
);
fnInfo
(
"tear down udf. udf name: %s, handle: %p
, ref count: %d"
,
stub
->
udfName
,
stub
->
handle
,
stub
->
refCount
);
doTeardownUdf
(
stub
->
handle
);
}
else
{
fnInfo
(
"udf still in use. udf name: %s, ref count: %d, last ref time: %"
PRId64
", handle: %p"
,
...
...
@@ -1530,12 +1533,15 @@ int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols,
}
SUdfcUvSession
*
session
=
handle
;
code
=
doCallUdfScalarFunc
(
handle
,
input
,
numOfCols
,
output
);
if
(
session
->
outputType
!=
output
->
columnData
->
info
.
type
||
session
->
outputLen
!=
output
->
columnData
->
info
.
bytes
)
{
fnError
(
"udfc scalar function calculate error, session type: %d(%d), output type: %d(%d)"
,
session
->
outputType
,
session
->
outputLen
,
output
->
columnData
->
info
.
type
,
output
->
columnData
->
info
.
bytes
);
if
(
output
->
columnData
==
NULL
)
{
fnError
(
"udfc scalar function calculate error. no column data"
);
code
=
TSDB_CODE_UDF_INVALID_OUTPUT_TYPE
;
}
else
{
if
(
session
->
outputType
!=
output
->
columnData
->
info
.
type
||
session
->
outputLen
!=
output
->
columnData
->
info
.
bytes
)
{
fnError
(
"udfc scalar function calculate error. type mismatch. session type: %d(%d), output type: %d(%d)"
,
session
->
outputType
,
session
->
outputLen
,
output
->
columnData
->
info
.
type
,
output
->
columnData
->
info
.
bytes
);
code
=
TSDB_CODE_UDF_INVALID_OUTPUT_TYPE
;
}
}
releaseUdfFuncHandle
(
udfName
);
return
code
;
...
...
@@ -1565,7 +1571,7 @@ int32_t doTeardownUdf(UdfcFuncHandle handle) {
fnInfo
(
"tear down udf. udf name: %s, udf func handle: %p"
,
session
->
udfName
,
handle
);
taosMemoryFree
(
task
->
session
);
taosMemoryFree
(
session
);
taosMemoryFree
(
task
);
return
err
;
...
...
@@ -1573,7 +1579,6 @@ int32_t doTeardownUdf(UdfcFuncHandle handle) {
//memory layout |---SUdfAggRes----|-----final result-----|---inter result----|
typedef
struct
SUdfAggRes
{
SUdfcUvSession
*
session
;
int8_t
finalResNum
;
int8_t
interResNum
;
char
*
finalResBuf
;
...
...
@@ -1606,7 +1611,6 @@ bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResult
udfRes
->
finalResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
);
udfRes
->
interResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
)
+
session
->
outputLen
;
udfRes
->
session
=
(
SUdfcUvSession
*
)
handle
;
SUdfInterBuf
buf
=
{
0
};
if
((
udfCode
=
doCallUdfAggInit
(
handle
,
&
buf
))
!=
0
)
{
fnError
(
"udfAggInit error. step doCallUdfAggInit. udf code: %d"
,
udfCode
);
...
...
@@ -1621,22 +1625,26 @@ bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResult
releaseUdfFuncHandle
(
pCtx
->
udfName
);
return
false
;
}
releaseUdfFuncHandle
(
pCtx
->
udfName
);
freeUdfInterBuf
(
&
buf
);
return
true
;
}
int32_t
udfAggProcess
(
struct
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
int32_t
numOfCols
=
pInput
->
numOfInputCols
;
int32_t
udfCode
=
0
;
UdfcFuncHandle
handle
=
0
;
if
((
udfCode
=
acquireUdfFuncHandle
((
char
*
)
pCtx
->
udfName
,
&
handle
))
!=
0
)
{
fnError
(
"udfAggProcess error. step acquireUdfFuncHandle. udf code: %d"
,
udfCode
);
return
udfCode
;
}
SUdfcUvSession
*
session
=
handle
;
SUdfAggRes
*
udfRes
=
(
SUdfAggRes
*
)
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
SUdfcUvSession
*
session
=
udfRes
->
session
;
if
(
session
==
NULL
)
{
return
TSDB_CODE_UDF_NO_FUNC_HANDLE
;
}
udfRes
->
finalResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
);
udfRes
->
interResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
)
+
session
->
outputLen
;
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
int32_t
numOfCols
=
pInput
->
numOfInputCols
;
int32_t
start
=
pInput
->
startRowIndex
;
int32_t
numOfRows
=
pInput
->
numOfRows
;
...
...
@@ -1664,7 +1672,7 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
.
numOfResult
=
udfRes
->
interResNum
};
SUdfInterBuf
newState
=
{
0
};
int32_t
udfCode
=
doCallUdfAggProcess
(
session
,
inputBlock
,
&
state
,
&
newState
);
udfCode
=
doCallUdfAggProcess
(
session
,
inputBlock
,
&
state
,
&
newState
);
if
(
udfCode
!=
0
)
{
fnError
(
"udfAggProcess error. code: %d"
,
udfCode
);
newState
.
numOfResult
=
0
;
...
...
@@ -1684,19 +1692,21 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
blockDataDestroy
(
inputBlock
);
taosArrayDestroy
(
tempBlock
.
pDataBlock
);
if
(
udfCode
!=
0
)
{
releaseUdfFuncHandle
(
pCtx
->
udfName
);
}
releaseUdfFuncHandle
(
pCtx
->
udfName
);
freeUdfInterBuf
(
&
newState
);
return
udfCode
;
}
int32_t
udfAggFinalize
(
struct
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SUdfAggRes
*
udfRes
=
(
SUdfAggRes
*
)
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
SUdfcUvSession
*
session
=
udfRes
->
session
;
if
(
session
==
NULL
)
{
return
TSDB_CODE_UDF_NO_FUNC_HANDLE
;
int32_t
udfCode
=
0
;
UdfcFuncHandle
handle
=
0
;
if
((
udfCode
=
acquireUdfFuncHandle
((
char
*
)
pCtx
->
udfName
,
&
handle
))
!=
0
)
{
fnError
(
"udfAggProcess error. step acquireUdfFuncHandle. udf code: %d"
,
udfCode
);
return
udfCode
;
}
SUdfcUvSession
*
session
=
handle
;
SUdfAggRes
*
udfRes
=
(
SUdfAggRes
*
)
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
udfRes
->
finalResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
);
udfRes
->
interResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
)
+
session
->
outputLen
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录