Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d668ee7b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
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看板
提交
d668ee7b
编写于
5月 17, 2022
作者:
S
slzhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: aggregate memory leaking
上级
c94c4395
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
73 addition
and
13 deletion
+73
-13
include/libs/function/tudf.h
include/libs/function/tudf.h
+4
-0
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+5
-2
source/libs/function/test/runUdf.c
source/libs/function/test/runUdf.c
+64
-11
未找到文件。
include/libs/function/tudf.h
浏览文件 @
d668ee7b
...
...
@@ -87,6 +87,7 @@ typedef struct SUdfInterBuf {
}
SUdfInterBuf
;
typedef
void
*
UdfcFuncHandle
;
//low level APIs
/**
* setup udf
* @param udf, in
...
...
@@ -115,6 +116,9 @@ int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t
*/
int32_t
doTeardownUdf
(
UdfcFuncHandle
handle
);
void
freeUdfInterBuf
(
SUdfInterBuf
*
buf
);
//high level APIs
bool
udfAggGetEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
udfAggInit
(
struct
SqlFunctionCtx
*
pCtx
,
struct
SResultRowEntryInfo
*
pResultCellInfo
);
int32_t
udfAggProcess
(
struct
SqlFunctionCtx
*
pCtx
);
...
...
source/libs/function/src/tudf.c
浏览文件 @
d668ee7b
...
...
@@ -836,7 +836,7 @@ int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode *
fnDebug
(
"udfc get uv task result. task: %p, uvTask: %p"
,
task
,
uvTask
);
if
(
uvTask
->
type
==
UV_TASK_REQ_RSP
)
{
if
(
uvTask
->
rspBuf
.
base
!=
NULL
)
{
SUdfResponse
rsp
;
SUdfResponse
rsp
=
{
0
}
;
void
*
buf
=
decodeUdfResponse
(
uvTask
->
rspBuf
.
base
,
&
rsp
);
assert
(
uvTask
->
rspBuf
.
len
==
POINTER_DISTANCE
(
buf
,
uvTask
->
rspBuf
.
base
));
task
->
errCode
=
rsp
.
code
;
...
...
@@ -1569,6 +1569,7 @@ bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResult
}
udfRes
->
interResNum
=
buf
.
numOfResult
;
memcpy
(
udfRes
->
interResBuf
,
buf
.
buf
,
buf
.
bufLen
);
freeUdfInterBuf
(
&
buf
);
return
true
;
}
...
...
@@ -1626,7 +1627,7 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
blockDataDestroy
(
inputBlock
);
taosArrayDestroy
(
tempBlock
.
pDataBlock
);
taosMemoryFree
(
newState
.
buf
);
freeUdfInterBuf
(
&
newState
);
return
udfCode
;
}
...
...
@@ -1655,6 +1656,8 @@ int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
GET_RES_INFO
(
pCtx
)
->
numOfRes
=
udfRes
->
finalResNum
;
}
freeUdfInterBuf
(
&
resultBuf
);
int32_t
numOfResults
=
functionFinalizeWithResultBuf
(
pCtx
,
pBlock
,
udfRes
->
finalResBuf
);
releaseUdfFuncHandle
(
pCtx
->
udfName
);
return
udfCallCode
==
0
?
numOfResults
:
udfCallCode
;
...
...
source/libs/function/test/runUdf.c
浏览文件 @
d668ee7b
...
...
@@ -34,17 +34,7 @@ static int32_t initLog() {
return
taosCreateLog
(
logName
,
1
,
configDir
,
NULL
,
NULL
,
NULL
,
NULL
,
0
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
parseArgs
(
argc
,
argv
);
initLog
();
if
(
taosInitCfg
(
configDir
,
NULL
,
NULL
,
NULL
,
NULL
,
0
)
!=
0
)
{
fnError
(
"failed to start since read config error"
);
return
-
1
;
}
udfcOpen
();
uv_sleep
(
1000
);
int
scalarFuncTest
()
{
UdfcFuncHandle
handle
;
if
(
doSetupUdf
(
"udf1"
,
&
handle
)
!=
0
)
{
...
...
@@ -87,5 +77,68 @@ int main(int argc, char *argv[]) {
taosMemoryFree
(
output
.
columnData
);
doTeardownUdf
(
handle
);
return
0
;
}
int
aggregateFuncTest
()
{
UdfcFuncHandle
handle
;
if
(
doSetupUdf
(
"udf2"
,
&
handle
)
!=
0
)
{
fnError
(
"setup udf failure"
);
return
-
1
;
}
SSDataBlock
block
=
{
0
};
SSDataBlock
*
pBlock
=
&
block
;
pBlock
->
pDataBlock
=
taosArrayInit
(
1
,
sizeof
(
SColumnInfoData
));
pBlock
->
info
.
numOfCols
=
1
;
pBlock
->
info
.
rows
=
4
;
char
data
[
16
]
=
{
0
};
char
bitmap
[
4
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
colInfo
=
{
0
};
colInfo
.
info
.
type
=
TSDB_DATA_TYPE_INT
;
colInfo
.
info
.
bytes
=
sizeof
(
int32_t
);
colInfo
.
info
.
colId
=
1
;
colInfo
.
pData
=
data
;
colInfo
.
nullbitmap
=
bitmap
;
for
(
int32_t
j
=
0
;
j
<
pBlock
->
info
.
rows
;
++
j
)
{
colDataAppendInt32
(
&
colInfo
,
j
,
&
j
);
}
taosArrayPush
(
pBlock
->
pDataBlock
,
&
colInfo
);
}
SUdfInterBuf
buf
=
{
0
};
SUdfInterBuf
newBuf
=
{
0
};
SUdfInterBuf
resultBuf
=
{
0
};
doCallUdfAggInit
(
handle
,
&
buf
);
doCallUdfAggProcess
(
handle
,
pBlock
,
&
buf
,
&
newBuf
);
taosArrayDestroy
(
pBlock
->
pDataBlock
);
doCallUdfAggFinalize
(
handle
,
&
newBuf
,
&
resultBuf
);
fprintf
(
stderr
,
"agg result: %f
\n
"
,
*
(
double
*
)
resultBuf
.
buf
);
freeUdfInterBuf
(
&
buf
);
freeUdfInterBuf
(
&
newBuf
);
freeUdfInterBuf
(
&
resultBuf
);
doTeardownUdf
(
handle
);
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
parseArgs
(
argc
,
argv
);
initLog
();
if
(
taosInitCfg
(
configDir
,
NULL
,
NULL
,
NULL
,
NULL
,
0
)
!=
0
)
{
fnError
(
"failed to start since read config error"
);
return
-
1
;
}
udfcOpen
();
uv_sleep
(
1000
);
scalarFuncTest
();
aggregateFuncTest
();
udfcClose
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录