Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0119054b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
0119054b
编写于
4月 28, 2022
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
aggregate function call from udfd
上级
974c679c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
80 addition
and
30 deletion
+80
-30
include/libs/function/tudf.h
include/libs/function/tudf.h
+2
-2
source/libs/function/src/udfd.c
source/libs/function/src/udfd.c
+78
-28
未找到文件。
include/libs/function/tudf.h
浏览文件 @
0119054b
...
...
@@ -139,9 +139,9 @@ typedef int32_t (*TUdfTeardownFunc)();
typedef
int32_t
(
*
TUdfFreeUdfColumnFunc
)(
SUdfColumn
*
column
);
typedef
int32_t
(
*
TUdfScalarProcFunc
)(
SUdfDataBlock
*
block
,
SUdfColumn
*
resultCol
);
typedef
int32_t
(
*
TUdfAgg
Ini
tFunc
)(
SUdfInterBuf
*
buf
);
typedef
int32_t
(
*
TUdfAgg
Star
tFunc
)(
SUdfInterBuf
*
buf
);
typedef
int32_t
(
*
TUdfAggProcessFunc
)(
SUdfDataBlock
*
block
,
SUdfInterBuf
*
interBuf
);
typedef
int32_t
(
*
TUdfAggFin
alize
Func
)(
SUdfInterBuf
*
buf
,
SUdfInterBuf
*
resultData
);
typedef
int32_t
(
*
TUdfAggFin
ish
Func
)(
SUdfInterBuf
*
buf
,
SUdfInterBuf
*
resultData
);
// end API to UDF writer
...
...
source/libs/function/src/udfd.c
浏览文件 @
0119054b
...
...
@@ -77,6 +77,10 @@ typedef struct SUdf {
uv_lib_t
lib
;
TUdfScalarProcFunc
scalarProcFunc
;
TUdfFreeUdfColumnFunc
freeUdfColumn
;
TUdfAggStartFunc
aggStartFunc
;
TUdfAggProcessFunc
aggProcFunc
;
TUdfAggFinishFunc
aggFinishFunc
;
}
SUdf
;
// TODO: low priority: change name onxxx to xxxCb, and udfc or udfd as prefix
...
...
@@ -97,15 +101,32 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
fnError
(
"can not load library %s. error: %s"
,
udf
->
path
,
uv_strerror
(
err
));
return
UDFC_CODE_LOAD_UDF_FAILURE
;
}
// TODO: find all the functions
char
normalFuncName
[
TSDB_FUNC_NAME_LEN
]
=
{
0
};
strcpy
(
normalFuncName
,
udfName
);
uv_dlsym
(
&
udf
->
lib
,
normalFuncName
,
(
void
**
)(
&
udf
->
scalarProcFunc
));
char
freeFuncName
[
TSDB_FUNC_NAME_LEN
+
6
]
=
{
0
};
char
*
freeSuffix
=
"_free"
;
strncpy
(
freeFuncName
,
normalFuncName
,
strlen
(
normalFuncName
));
strncat
(
freeFuncName
,
freeSuffix
,
strlen
(
freeSuffix
));
uv_dlsym
(
&
udf
->
lib
,
freeFuncName
,
(
void
**
)(
&
udf
->
freeUdfColumn
));
//TODO: init and destroy function
if
(
udf
->
funcType
==
TSDB_FUNC_TYPE_SCALAR
)
{
char
processFuncName
[
TSDB_FUNC_NAME_LEN
]
=
{
0
};
strcpy
(
processFuncName
,
udfName
);
uv_dlsym
(
&
udf
->
lib
,
processFuncName
,
(
void
**
)(
&
udf
->
scalarProcFunc
));
char
freeFuncName
[
TSDB_FUNC_NAME_LEN
+
5
]
=
{
0
};
char
*
freeSuffix
=
"_free"
;
strncpy
(
freeFuncName
,
processFuncName
,
strlen
(
processFuncName
));
strncat
(
freeFuncName
,
freeSuffix
,
strlen
(
freeSuffix
));
uv_dlsym
(
&
udf
->
lib
,
freeFuncName
,
(
void
**
)(
&
udf
->
freeUdfColumn
));
}
else
if
(
udf
->
funcType
==
TSDB_FUNC_TYPE_AGGREGATE
)
{
char
processFuncName
[
TSDB_FUNC_NAME_LEN
]
=
{
0
};
strcpy
(
processFuncName
,
udfName
);
uv_dlsym
(
&
udf
->
lib
,
processFuncName
,
(
void
**
)(
&
udf
->
aggProcFunc
));
char
startFuncName
[
TSDB_FUNC_NAME_LEN
+
6
]
=
{
0
};
char
*
startSuffix
=
"_start"
;
strncpy
(
startFuncName
,
processFuncName
,
strlen
(
processFuncName
));
strncat
(
startFuncName
,
startSuffix
,
strlen
(
startSuffix
));
uv_dlsym
(
&
udf
->
lib
,
startFuncName
,
(
void
**
)(
&
udf
->
aggStartFunc
));
char
finishFuncName
[
TSDB_FUNC_NAME_LEN
+
7
]
=
{
0
};
char
*
finishSuffix
=
"_finish"
;
strncpy
(
finishFuncName
,
processFuncName
,
strlen
(
processFuncName
));
strncat
(
finishFuncName
,
finishSuffix
,
strlen
(
finishSuffix
));
uv_dlsym
(
&
udf
->
lib
,
startFuncName
,
(
void
**
)(
&
udf
->
aggFinishFunc
));
//TODO: merge
}
return
0
;
}
...
...
@@ -181,26 +202,58 @@ void udfdProcessRequest(uv_work_t *req) {
call
->
udfHandle
);
SUdfcFuncHandle
*
handle
=
(
SUdfcFuncHandle
*
)(
call
->
udfHandle
);
SUdf
*
udf
=
handle
->
udf
;
SUdfDataBlock
input
=
{
0
};
convertDataBlockToUdfDataBlock
(
&
call
->
block
,
&
input
);
SUdfColumn
output
=
{
0
};
// TODO: call different functions according to call type, for now just calar
if
(
call
->
callType
==
TSDB_UDF_CALL_SCALA_PROC
)
{
udf
->
scalarProcFunc
(
&
input
,
&
output
);
}
SUdfResponse
response
=
{
0
};
SUdfResponse
*
rsp
=
&
response
;
if
(
call
->
callType
==
TSDB_UDF_CALL_SCALA_PROC
)
{
rsp
->
seqNum
=
request
.
seqNum
;
rsp
->
type
=
request
.
type
;
rsp
->
code
=
0
;
SUdfCallResponse
*
subRsp
=
&
rsp
->
callRsp
;
subRsp
->
callType
=
call
->
callType
;
convertUdfColumnToDataBlock
(
&
output
,
&
subRsp
->
resultData
);
SUdfCallResponse
*
subRsp
=
&
rsp
->
callRsp
;
switch
(
call
->
callType
)
{
case
TSDB_UDF_CALL_SCALA_PROC
:
{
SUdfColumn
output
=
{
0
};
SUdfDataBlock
input
=
{
0
};
convertDataBlockToUdfDataBlock
(
&
call
->
block
,
&
input
);
udf
->
scalarProcFunc
(
&
input
,
&
output
);
convertUdfColumnToDataBlock
(
&
output
,
&
response
.
callRsp
.
resultData
);
udf
->
freeUdfColumn
(
&
output
);
break
;
}
case
TSDB_UDF_CALL_AGG_INIT
:
{
SUdfInterBuf
outBuf
=
{.
buf
=
taosMemoryMalloc
(
udf
->
bufSize
),
.
bufLen
=
udf
->
bufSize
,
.
numOfResult
=
0
};
udf
->
aggStartFunc
(
&
outBuf
);
subRsp
->
resultBuf
=
outBuf
;
break
;
}
case
TSDB_UDF_CALL_AGG_PROC
:
{
SUdfDataBlock
input
=
{
0
};
convertDataBlockToUdfDataBlock
(
&
call
->
block
,
&
input
);
SUdfInterBuf
outBuf
=
{.
buf
=
taosMemoryMalloc
(
udf
->
bufSize
),
.
bufLen
=
udf
->
bufSize
,
.
numOfResult
=
0
};
udf
->
aggProcFunc
(
&
input
,
&
outBuf
);
subRsp
->
resultBuf
=
outBuf
;
break
;
}
case
TSDB_UDF_CALL_AGG_FIN
:
{
SUdfInterBuf
outBuf
=
{.
buf
=
taosMemoryMalloc
(
udf
->
bufSize
),
.
bufLen
=
udf
->
bufSize
,
.
numOfResult
=
0
};
udf
->
aggFinishFunc
(
&
call
->
interBuf
,
&
outBuf
);
subRsp
->
resultBuf
=
outBuf
;
break
;
}
default:
break
;
}
rsp
->
seqNum
=
request
.
seqNum
;
rsp
->
type
=
request
.
type
;
rsp
->
code
=
0
;
subRsp
->
callType
=
call
->
callType
;
int32_t
len
=
encodeUdfResponse
(
NULL
,
rsp
);
rsp
->
msgLen
=
len
;
void
*
bufBegin
=
taosMemoryMalloc
(
len
);
...
...
@@ -208,9 +261,6 @@ void udfdProcessRequest(uv_work_t *req) {
encodeUdfResponse
(
&
buf
,
rsp
);
uvUdf
->
output
=
uv_buf_init
(
bufBegin
,
len
);
// TODO: free udf column
udf
->
freeUdfColumn
(
&
output
);
taosMemoryFree
(
uvUdf
->
input
.
base
);
break
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录