Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f8e71908
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看板
提交
f8e71908
编写于
4月 25, 2022
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add feature that udaf produces no result
上级
73a0ad74
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
21 deletion
+31
-21
source/libs/function/inc/tudf.h
source/libs/function/inc/tudf.h
+2
-4
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+29
-17
未找到文件。
source/libs/function/inc/tudf.h
浏览文件 @
f8e71908
...
@@ -42,8 +42,7 @@ enum {
...
@@ -42,8 +42,7 @@ enum {
UDFC_CODE_INVALID_STATE
=
-
5
UDFC_CODE_INVALID_STATE
=
-
5
};
};
typedef
void
*
UdfcFuncHandle
;
/**
/**
* setup udf
* setup udf
...
@@ -95,10 +94,9 @@ typedef struct SUdfDataBlock {
...
@@ -95,10 +94,9 @@ typedef struct SUdfDataBlock {
typedef
struct
SUdfInterBuf
{
typedef
struct
SUdfInterBuf
{
int32_t
bufLen
;
int32_t
bufLen
;
char
*
buf
;
char
*
buf
;
int8_t
numOfResult
;
//zero or one
}
SUdfInterBuf
;
}
SUdfInterBuf
;
typedef
void
*
UdfcFuncHandle
;
// output: interBuf
// output: interBuf
int32_t
callUdfAggInit
(
UdfcFuncHandle
handle
,
SUdfInterBuf
*
interBuf
);
int32_t
callUdfAggInit
(
UdfcFuncHandle
handle
,
SUdfInterBuf
*
interBuf
);
// input: block, state
// input: block, state
...
...
source/libs/function/src/tudf.c
浏览文件 @
f8e71908
...
@@ -241,12 +241,14 @@ void* decodeUdfSetupRequest(const void* buf, SUdfSetupRequest *request) {
...
@@ -241,12 +241,14 @@ void* decodeUdfSetupRequest(const void* buf, SUdfSetupRequest *request) {
int32_t
encodeUdfInterBuf
(
void
**
buf
,
const
SUdfInterBuf
*
state
)
{
int32_t
encodeUdfInterBuf
(
void
**
buf
,
const
SUdfInterBuf
*
state
)
{
int32_t
len
=
0
;
int32_t
len
=
0
;
len
+=
taosEncodeFixedI8
(
buf
,
state
->
numOfResult
);
len
+=
taosEncodeFixedI32
(
buf
,
state
->
bufLen
);
len
+=
taosEncodeFixedI32
(
buf
,
state
->
bufLen
);
len
+=
taosEncodeBinary
(
buf
,
state
->
buf
,
state
->
bufLen
);
len
+=
taosEncodeBinary
(
buf
,
state
->
buf
,
state
->
bufLen
);
return
len
;
return
len
;
}
}
void
*
decodeUdfInterBuf
(
const
void
*
buf
,
SUdfInterBuf
*
state
)
{
void
*
decodeUdfInterBuf
(
const
void
*
buf
,
SUdfInterBuf
*
state
)
{
buf
=
taosDecodeFixedI8
(
buf
,
&
state
->
numOfResult
);
buf
=
taosDecodeFixedI32
(
buf
,
&
state
->
bufLen
);
buf
=
taosDecodeFixedI32
(
buf
,
&
state
->
bufLen
);
buf
=
taosDecodeBinary
(
buf
,
(
void
**
)
&
state
->
buf
,
state
->
bufLen
);
buf
=
taosDecodeBinary
(
buf
,
(
void
**
)
&
state
->
buf
,
state
->
bufLen
);
return
(
void
*
)
buf
;
return
(
void
*
)
buf
;
...
@@ -1250,41 +1252,44 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
...
@@ -1250,41 +1252,44 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
char
*
udfRes
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
char
*
udfRes
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
// computing based on the true data block
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
int32_t
start
=
pInput
->
startRowIndex
;
int32_t
start
=
pInput
->
startRowIndex
;
int32_t
numOfRows
=
pInput
->
numOfRows
;
int32_t
numOfRows
=
pInput
->
numOfRows
;
// TODO: range [start, start+numOfRow) to generate colInfoData
UdfcFuncHandle
handle
=
(
UdfcFuncHandle
)(
*
(
int64_t
*
)(
udfRes
));
UdfcFuncHandle
handle
=
(
UdfcFuncHandle
)(
*
(
int64_t
*
)(
udfRes
));
SUdfUvSession
*
session
=
(
SUdfUvSession
*
)
handle
;
SUdfUvSession
*
session
=
(
SUdfUvSession
*
)
handle
;
SSDataBlock
input
=
{
0
};
SSDataBlock
tempBlock
=
{
0
};
input
.
info
.
numOfCols
=
numOfCols
;
tempBlock
.
info
.
numOfCols
=
numOfCols
;
input
.
info
.
rows
=
numOfRows
;
tempBlock
.
info
.
rows
=
numOfRows
;
input
.
info
.
uid
=
pInput
->
uid
;
tempBlock
.
info
.
uid
=
pInput
->
uid
;
bool
hasVarCol
=
false
;
bool
hasVarCol
=
false
;
input
.
pDataBlock
=
taosArrayInit
(
numOfCols
,
sizeof
(
SColumnInfoData
));
tempBlock
.
pDataBlock
=
taosArrayInit
(
numOfCols
,
sizeof
(
SColumnInfoData
));
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
col
=
pInput
->
pData
[
i
];
SColumnInfoData
*
col
=
pInput
->
pData
[
i
];
if
(
IS_VAR_DATA_TYPE
(
col
->
info
.
type
))
{
if
(
IS_VAR_DATA_TYPE
(
col
->
info
.
type
))
{
hasVarCol
=
true
;
hasVarCol
=
true
;
}
}
taosArrayPush
(
input
.
pDataBlock
,
col
);
taosArrayPush
(
tempBlock
.
pDataBlock
,
col
);
}
}
tempBlock
.
info
.
hasVarCol
=
hasVarCol
;
input
.
info
.
hasVarCol
=
hasVarCol
;
SSDataBlock
*
inputBlock
=
blockDataExtractBlock
(
&
tempBlock
,
start
,
numOfRows
);
SUdfInterBuf
state
=
{.
buf
=
udfRes
+
sizeof
(
int64_t
)
+
session
->
outputLen
,
.
bufLen
=
session
->
bufSize
};
SUdfInterBuf
state
=
{.
buf
=
udfRes
+
sizeof
(
int64_t
)
+
session
->
outputLen
,
.
bufLen
=
session
->
bufSize
,
.
numOfResult
=
GET_RES_INFO
(
pCtx
)
->
numOfRes
};
SUdfInterBuf
newState
=
{
0
};
SUdfInterBuf
newState
=
{
0
};
callUdfAggProcess
(
handle
,
&
input
,
&
state
,
&
newState
);
callUdfAggProcess
(
handle
,
inputBlock
,
&
state
,
&
newState
);
memcpy
(
state
.
buf
,
newState
.
buf
,
newState
.
bufLen
);
memcpy
(
state
.
buf
,
newState
.
buf
,
newState
.
bufLen
);
taosArrayDestroy
(
input
.
pDataBlock
);
GET_RES_INFO
(
pCtx
)
->
numOfRes
=
(
newState
.
numOfResult
==
1
?
1
:
0
);
blockDataDestroy
(
inputBlock
);
taosArrayDestroy
(
tempBlock
.
pDataBlock
);
taosMemoryFree
(
newState
.
buf
);
taosMemoryFree
(
newState
.
buf
);
return
0
;
return
0
;
...
@@ -1296,10 +1301,17 @@ int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
...
@@ -1296,10 +1301,17 @@ int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
UdfcFuncHandle
handle
=
(
UdfcFuncHandle
)(
*
(
int64_t
*
)(
udfRes
));
UdfcFuncHandle
handle
=
(
UdfcFuncHandle
)(
*
(
int64_t
*
)(
udfRes
));
SUdfUvSession
*
session
=
(
SUdfUvSession
*
)
handle
;
SUdfUvSession
*
session
=
(
SUdfUvSession
*
)
handle
;
SUdfInterBuf
resultBuf
=
{.
buf
=
udfRes
+
sizeof
(
int64_t
),
.
bufLen
=
session
->
outputLen
};
SUdfInterBuf
resultBuf
=
{.
buf
=
udfRes
+
sizeof
(
int64_t
),
SUdfInterBuf
state
=
{.
buf
=
udfRes
+
sizeof
(
int64_t
)
+
session
->
outputLen
,
.
bufLen
=
session
->
bufSize
};
.
bufLen
=
session
->
outputLen
};
SUdfInterBuf
state
=
{.
buf
=
udfRes
+
sizeof
(
int64_t
)
+
session
->
outputLen
,
.
bufLen
=
session
->
bufSize
,
.
numOfResult
=
GET_RES_INFO
(
pCtx
)
->
numOfRes
};
callUdfAggFinalize
(
handle
,
&
state
,
&
resultBuf
);
callUdfAggFinalize
(
handle
,
&
state
,
&
resultBuf
);
GET_RES_INFO
(
pCtx
)
->
numOfRes
=
(
resultBuf
.
numOfResult
==
1
?
1
:
0
);
functionFinalize
(
pCtx
,
pBlock
);
functionFinalize
(
pCtx
,
pBlock
);
teardownUdf
(
handle
);
teardownUdf
(
handle
);
return
0
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录