Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
18943125
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
18943125
编写于
4月 17, 2022
作者:
S
slzhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
call udf for scalar and aggregate
上级
4817f54a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
135 addition
and
25 deletion
+135
-25
source/libs/function/inc/tudf.h
source/libs/function/inc/tudf.h
+11
-10
source/libs/function/inc/tudfInt.h
source/libs/function/inc/tudfInt.h
+4
-1
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+117
-11
source/libs/function/src/udfd.c
source/libs/function/src/udfd.c
+3
-3
未找到文件。
source/libs/function/inc/tudf.h
浏览文件 @
18943125
...
...
@@ -99,19 +99,20 @@ typedef struct SUdfInterBuf {
}
SUdfInterBuf
;
//TODO: translate these calls to callUdf
int32_t
callUdfAggInit
(
SUdfInterBuf
*
interBuf
);
// input: block, initFirst
// output: interbuf
int32_t
callUdfAggProcess
(
SSDataBlock
*
block
,
SUdfInterBuf
*
interBuf
);
// output: interBuf
int32_t
callUdfAggInit
(
UdfHandle
handle
,
SUdfInterBuf
*
interBuf
);
// input: block, state
// output: newState
int32_t
callUdfAggProcess
(
UdfHandle
handle
,
SSDataBlock
*
block
,
SUdfInterBuf
*
state
,
SUdfInterBuf
*
newState
);
// input: interBuf
// output: resultData
int32_t
callUdfAggFinalize
(
SUdfInterBuf
*
interBuf
,
SSDataBlock
*
resultData
);
int32_t
callUdfAggFinalize
(
UdfHandle
handle
,
SUdfInterBuf
*
interBuf
,
SUdfInterBuf
*
resultData
);
// input: interbuf1, interbuf2
// output: resultBuf
int32_t
callUdfAggMerge
(
SUdfInterBuf
*
interBuf1
,
SUdfInterBuf
*
interBuf2
,
SUdfInterBuf
*
resultBuf
);
int32_t
callUdfAggMerge
(
UdfHandle
handle
,
SUdfInterBuf
*
interBuf1
,
SUdfInterBuf
*
interBuf2
,
SUdfInterBuf
*
resultBuf
);
// input: block
// output: resultData
int32_t
callUdfScalaProcess
(
SSDataBlock
*
block
,
SSDataBlock
*
resultData
);
int32_t
callUdfScalaProcess
(
UdfHandle
handle
,
SSDataBlock
*
block
,
SSDataBlock
*
resultData
);
/**
* tearn down udf
...
...
@@ -134,12 +135,12 @@ typedef int32_t (*TUdfTeardownFunc)();
//typedef int32_t addFixedLengthColumnData(SColumnData *columnData, int rowIndex, bool isNull, int32_t colBytes, char* data);
//typedef int32_t addVariableLengthColumnData(SColumnData *columnData, int rowIndex, bool isNull, int32_t dataLen, char * data);
typedef
int32_t
(
*
TUdfFreeUdfColumnDataFunc
)(
SUdfColumn
Data
*
columnData
);
typedef
int32_t
(
*
TUdfFreeUdfColumnDataFunc
)(
SUdfColumn
*
columnData
);
typedef
int32_t
(
*
TUdfScalarProcFunc
)(
SUdfDataBlock
block
,
SUdfColumn
Data
*
resultData
);
typedef
int32_t
(
*
TUdfScalarProcFunc
)(
SUdfDataBlock
block
,
SUdfColumn
*
resultCol
);
typedef
int32_t
(
*
TUdfAggInitFunc
)(
SUdfInterBuf
*
buf
);
typedef
int32_t
(
*
TUdfAggProcessFunc
)(
SUdfDataBlock
block
,
SUdfInterBuf
*
interBuf
);
typedef
int32_t
(
*
TUdfAggFinalizeFunc
)(
SUdfInterBuf
buf
,
SUdf
ColumnData
*
resultData
);
typedef
int32_t
(
*
TUdfAggFinalizeFunc
)(
SUdfInterBuf
buf
,
SUdf
InterBuf
*
resultData
);
// end API to UDF writer
...
...
source/libs/function/inc/tudfInt.h
浏览文件 @
18943125
...
...
@@ -59,7 +59,7 @@ typedef struct SUdfCallRequest {
typedef
struct
SUdfCallResponse
{
int8_t
callType
;
SSDataBlock
resultData
;
SUdfInterBuf
inter
Buf
;
SUdfInterBuf
result
Buf
;
}
SUdfCallResponse
;
...
...
@@ -106,6 +106,9 @@ void freeUdfColumnData(SUdfColumnData *data);
void
freeUdfColumn
(
SUdfColumn
*
col
);
void
freeUdfDataDataBlock
(
SUdfDataBlock
*
block
);
int32_t
convertDataBlockToUdfDataBlock
(
SSDataBlock
*
block
,
SUdfDataBlock
*
udfBlock
);
int32_t
convertUdfColumnToDataBlock
(
SUdfColumn
*
udfCol
,
SSDataBlock
*
block
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/function/src/tudf.c
浏览文件 @
18943125
...
...
@@ -18,6 +18,7 @@
#include "tudf.h"
#include "tudfInt.h"
#include "tarray.h"
#include "tdatablock.h"
//TODO: when startup, set thread poll size. add it to cfg
//TODO: test for udfd restart
...
...
@@ -351,13 +352,13 @@ int32_t encodeUdfCallResponse(void **buf, const SUdfCallResponse *callRsp) {
len
+=
tEncodeDataBlock
(
buf
,
&
callRsp
->
resultData
);
break
;
case
TSDB_UDF_CALL_AGG_INIT
:
len
+=
encodeUdfInterBuf
(
buf
,
&
callRsp
->
inter
Buf
);
len
+=
encodeUdfInterBuf
(
buf
,
&
callRsp
->
result
Buf
);
break
;
case
TSDB_UDF_CALL_AGG_PROC
:
len
+=
encodeUdfInterBuf
(
buf
,
&
callRsp
->
inter
Buf
);
len
+=
encodeUdfInterBuf
(
buf
,
&
callRsp
->
result
Buf
);
break
;
case
TSDB_UDF_CALL_AGG_MERGE
:
len
+=
encodeUdfInterBuf
(
buf
,
&
callRsp
->
inter
Buf
);
len
+=
encodeUdfInterBuf
(
buf
,
&
callRsp
->
result
Buf
);
break
;
case
TSDB_UDF_CALL_AGG_FIN
:
len
+=
tEncodeDataBlock
(
buf
,
&
callRsp
->
resultData
);
...
...
@@ -373,13 +374,13 @@ void* decodeUdfCallResponse(const void* buf, SUdfCallResponse* callRsp) {
buf
=
tDecodeDataBlock
(
buf
,
&
callRsp
->
resultData
);
break
;
case
TSDB_UDF_CALL_AGG_INIT
:
buf
=
decodeUdfInterBuf
(
buf
,
&
callRsp
->
inter
Buf
);
buf
=
decodeUdfInterBuf
(
buf
,
&
callRsp
->
result
Buf
);
break
;
case
TSDB_UDF_CALL_AGG_PROC
:
buf
=
decodeUdfInterBuf
(
buf
,
&
callRsp
->
inter
Buf
);
buf
=
decodeUdfInterBuf
(
buf
,
&
callRsp
->
result
Buf
);
break
;
case
TSDB_UDF_CALL_AGG_MERGE
:
buf
=
decodeUdfInterBuf
(
buf
,
&
callRsp
->
inter
Buf
);
buf
=
decodeUdfInterBuf
(
buf
,
&
callRsp
->
result
Buf
);
break
;
case
TSDB_UDF_CALL_AGG_FIN
:
buf
=
tDecodeDataBlock
(
buf
,
&
callRsp
->
resultData
);
...
...
@@ -483,6 +484,70 @@ void freeUdfInterBuf(SUdfInterBuf *buf) {
buf
->
buf
=
NULL
;
}
int32_t
convertDataBlockToUdfDataBlock
(
SSDataBlock
*
block
,
SUdfDataBlock
*
udfBlock
)
{
udfBlock
->
numOfRows
=
block
->
info
.
rows
;
udfBlock
->
numOfCols
=
block
->
info
.
numOfCols
;
udfBlock
->
udfCols
=
taosMemoryMalloc
(
sizeof
(
SUdfColumn
*
)
*
udfBlock
->
numOfCols
);
for
(
int32_t
i
=
0
;
i
<
udfBlock
->
numOfCols
;
++
i
)
{
udfBlock
->
udfCols
[
i
]
=
taosMemoryMalloc
(
sizeof
(
SUdfColumn
));
SColumnInfoData
*
col
=
(
SColumnInfoData
*
)
taosArrayGet
(
block
->
pDataBlock
,
i
);
SUdfColumn
*
udfCol
=
udfBlock
->
udfCols
[
i
];
udfCol
->
colMeta
.
type
=
col
->
info
.
type
;
udfCol
->
colMeta
.
bytes
=
col
->
info
.
bytes
;
udfCol
->
colMeta
.
scale
=
col
->
info
.
scale
;
udfCol
->
colMeta
.
precision
=
col
->
info
.
precision
;
udfCol
->
colData
.
numOfRows
=
udfBlock
->
numOfRows
;
udfCol
->
colData
.
varLengthColumn
=
IS_VAR_DATA_TYPE
(
udfCol
->
colMeta
.
type
);
if
(
udfCol
->
colData
.
varLengthColumn
)
{
udfCol
->
colData
.
varOffsetsLen
=
sizeof
(
int32_t
)
*
udfBlock
->
numOfRows
;
udfCol
->
colData
.
varOffsets
=
taosMemoryMalloc
(
udfCol
->
colData
.
varOffsetsLen
);
memcpy
(
udfCol
->
colData
.
varOffsets
,
col
->
varmeta
.
offset
,
udfCol
->
colData
.
varOffsetsLen
);
udfCol
->
colData
.
payloadLen
=
colDataGetLength
(
col
,
udfBlock
->
numOfRows
);
udfCol
->
colData
.
payload
=
taosMemoryMalloc
(
udfCol
->
colData
.
payloadLen
);
memcpy
(
udfCol
->
colData
.
payload
,
col
->
pData
,
udfCol
->
colData
.
payloadLen
);
}
else
{
udfCol
->
colData
.
nullBitmapLen
=
BitmapLen
(
udfCol
->
colData
.
numOfRows
);
udfCol
->
colData
.
nullBitmap
=
taosMemoryMalloc
(
udfCol
->
colData
.
nullBitmapLen
);
memcpy
(
udfCol
->
colData
.
nullBitmap
,
col
->
nullbitmap
,
udfCol
->
colData
.
nullBitmapLen
);
udfCol
->
colData
.
dataLen
=
colDataGetLength
(
col
,
udfBlock
->
numOfRows
);
udfCol
->
colData
.
data
=
taosMemoryMalloc
(
udfCol
->
colData
.
dataLen
);
memcpy
(
udfCol
->
colData
.
data
,
col
->
pData
,
udfCol
->
colData
.
dataLen
);
}
}
return
0
;
}
int32_t
convertUdfColumnToDataBlock
(
SUdfColumn
*
udfCol
,
SSDataBlock
*
block
)
{
block
->
info
.
numOfCols
=
1
;
block
->
info
.
rows
=
udfCol
->
colData
.
numOfRows
;
block
->
info
.
hasVarCol
=
udfCol
->
colData
.
varLengthColumn
;
block
->
pDataBlock
=
taosArrayInit
(
1
,
sizeof
(
SColumnInfoData
));
taosArraySetSize
(
block
->
pDataBlock
,
1
);
SColumnInfoData
*
col
=
taosArrayGet
(
block
->
pDataBlock
,
0
);
SUdfColumnMeta
*
meta
=
&
udfCol
->
colMeta
;
col
->
info
.
precision
=
meta
->
precision
;
col
->
info
.
bytes
=
meta
->
bytes
;
col
->
info
.
scale
=
meta
->
scale
;
col
->
info
.
type
=
meta
->
type
;
SUdfColumnData
*
data
=
&
udfCol
->
colData
;
if
(
!
IS_VAR_DATA_TYPE
(
meta
->
type
))
{
col
->
nullbitmap
=
taosMemoryMalloc
(
data
->
nullBitmapLen
);
memcpy
(
col
->
nullbitmap
,
data
->
nullBitmap
,
data
->
nullBitmapLen
);
col
->
pData
=
taosMemoryMalloc
(
data
->
dataLen
);
memcpy
(
col
->
pData
,
data
->
payload
,
data
->
dataLen
);
}
else
{
col
->
varmeta
.
offset
=
taosMemoryMalloc
(
data
->
varOffsetsLen
);
memcpy
(
col
->
varmeta
.
offset
,
data
->
varOffsets
,
data
->
varOffsetsLen
);
col
->
pData
=
taosMemoryMalloc
(
data
->
payloadLen
);
memcpy
(
col
->
pData
,
data
->
payload
,
data
->
payloadLen
);
}
return
0
;
}
void
onUdfcPipeClose
(
uv_handle_t
*
handle
)
{
SClientUvConn
*
conn
=
handle
->
data
;
if
(
!
QUEUE_EMPTY
(
&
conn
->
taskQueue
))
{
...
...
@@ -962,7 +1027,7 @@ int32_t setupUdf(char udfName[], SEpSet *epSet, UdfHandle *handle) {
return
err
;
}
int32_t
callUdf
(
UdfHandle
handle
,
int8_t
callType
,
int8_t
initFirst
,
SSDataBlock
*
input
,
SUdfInterBuf
*
state
,
SUdfInterBuf
*
state2
,
int32_t
callUdf
(
UdfHandle
handle
,
int8_t
callType
,
SSDataBlock
*
input
,
SUdfInterBuf
*
state
,
SUdfInterBuf
*
state2
,
SSDataBlock
*
output
,
SUdfInterBuf
*
newState
)
{
debugPrint
(
"%s"
,
"client call udf"
);
...
...
@@ -1002,19 +1067,19 @@ int32_t callUdf(UdfHandle handle, int8_t callType, int8_t initFirst, SSDataBlock
SUdfCallResponse
*
rsp
=
&
task
->
_call
.
rsp
;
switch
(
callType
)
{
case
TSDB_UDF_CALL_AGG_INIT
:
{
*
newState
=
rsp
->
inter
Buf
;
*
newState
=
rsp
->
result
Buf
;
break
;
}
case
TSDB_UDF_CALL_AGG_PROC
:
{
*
newState
=
rsp
->
inter
Buf
;
*
newState
=
rsp
->
result
Buf
;
break
;
}
case
TSDB_UDF_CALL_AGG_MERGE
:
{
*
newState
=
rsp
->
inter
Buf
;
*
newState
=
rsp
->
result
Buf
;
break
;
}
case
TSDB_UDF_CALL_AGG_FIN
:
{
*
output
=
rsp
->
resultData
;
*
newState
=
rsp
->
resultBuf
;
break
;
}
case
TSDB_UDF_CALL_SCALA_PROC
:
{
...
...
@@ -1027,6 +1092,47 @@ int32_t callUdf(UdfHandle handle, int8_t callType, int8_t initFirst, SSDataBlock
return
task
->
errCode
;
}
//TODO: translate these calls to callUdf
int32_t
callUdfAggInit
(
UdfHandle
handle
,
SUdfInterBuf
*
interBuf
)
{
int8_t
callType
=
TSDB_UDF_CALL_AGG_INIT
;
int32_t
err
=
callUdf
(
handle
,
callType
,
NULL
,
NULL
,
NULL
,
NULL
,
interBuf
);
return
err
;
}
// input: block, state
// output: interbuf,
int32_t
callUdfAggProcess
(
UdfHandle
handle
,
SSDataBlock
*
block
,
SUdfInterBuf
*
state
,
SUdfInterBuf
*
newState
)
{
int8_t
callType
=
TSDB_UDF_CALL_AGG_PROC
;
int32_t
err
=
callUdf
(
handle
,
callType
,
block
,
state
,
NULL
,
NULL
,
newState
);
return
err
;
}
// input: interbuf1, interbuf2
// output: resultBuf
int32_t
callUdfAggMerge
(
UdfHandle
handle
,
SUdfInterBuf
*
interBuf1
,
SUdfInterBuf
*
interBuf2
,
SUdfInterBuf
*
resultBuf
)
{
int8_t
callType
=
TSDB_UDF_CALL_AGG_MERGE
;
int32_t
err
=
callUdf
(
handle
,
callType
,
NULL
,
interBuf1
,
interBuf2
,
NULL
,
resultBuf
);
return
err
;
}
// input: interBuf
// output: resultData
int32_t
callUdfAggFinalize
(
UdfHandle
handle
,
SUdfInterBuf
*
interBuf
,
SUdfInterBuf
*
resultData
)
{
int8_t
callType
=
TSDB_UDF_CALL_AGG_PROC
;
int32_t
err
=
callUdf
(
handle
,
callType
,
NULL
,
interBuf
,
NULL
,
NULL
,
resultData
);
return
err
;
}
// input: block
// output: resultData
int32_t
callUdfScalaProcess
(
UdfHandle
handle
,
SSDataBlock
*
block
,
SSDataBlock
*
resultData
)
{
int8_t
callType
=
TSDB_UDF_CALL_SCALA_PROC
;
int32_t
err
=
callUdf
(
handle
,
callType
,
block
,
NULL
,
NULL
,
resultData
,
NULL
);
return
err
;
}
int32_t
teardownUdf
(
UdfHandle
handle
)
{
debugPrint
(
"%s"
,
"client teardown udf"
);
...
...
source/libs/function/src/udfd.c
浏览文件 @
18943125
...
...
@@ -112,8 +112,8 @@ void udfdProcessRequest(uv_work_t *req) {
SUdf
*
udf
=
handle
->
udf
;
SUdfDataBlock
input
=
{
0
};
//TODO: convertSDataBlockToUdfDataBlock(
call->block, &input);
SUdfColumn
Data
output
;
convertDataBlockToUdfDataBlock
(
&
call
->
block
,
&
input
);
SUdfColumn
output
;
//TODO: call different functions according to call type, for now just calar
if
(
call
->
callType
==
TSDB_UDF_CALL_SCALA_PROC
)
{
udf
->
scalarProcFunc
(
input
,
&
output
);
...
...
@@ -126,7 +126,7 @@ void udfdProcessRequest(uv_work_t *req) {
rsp
->
type
=
request
.
type
;
rsp
->
code
=
0
;
SUdfCallResponse
*
subRsp
=
&
rsp
->
callRsp
;
//TODO: convertSUdfColumnDataToSSDataBlock(
output, &subRsp->resultData);
convertUdfColumnToDataBlock
(
&
output
,
&
subRsp
->
resultData
);
}
int32_t
len
=
encodeUdfResponse
(
NULL
,
rsp
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录