Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
57f252d1
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
未验证
提交
57f252d1
编写于
11月 04, 2021
作者:
H
Hui Li
提交者:
GitHub
11月 04, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8489 from taosdata/udf_master_reload
[TD-6137]<test>:add test case for udf to support all query ways
上级
2f3f2976
90a037c4
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
434 addition
and
188 deletion
+434
-188
tests/pytest/query/udf.py
tests/pytest/query/udf.py
+368
-123
tests/script/general/parser/udf_dll.sim
tests/script/general/parser/udf_dll.sim
+1
-1
tests/script/general/parser/udf_dll_stable.sim
tests/script/general/parser/udf_dll_stable.sim
+1
-1
tests/script/sh/abs_max.c
tests/script/sh/abs_max.c
+31
-26
tests/script/sh/add_one.c
tests/script/sh/add_one.c
+5
-7
tests/script/sh/add_one_64232.c
tests/script/sh/add_one_64232.c
+2
-4
tests/script/sh/sum_double.c
tests/script/sh/sum_double.c
+26
-26
未找到文件。
tests/pytest/query/udf.py
浏览文件 @
57f252d1
此差异已折叠。
点击以展开。
tests/script/general/parser/udf_dll.sim
浏览文件 @
57f252d1
...
...
@@ -10,7 +10,7 @@ sql connect
print ======================== dnode1 start
sql create function add_one as '/tmp/add_one.so' outputtype int;
sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype int;
sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype
big
int;
sql show functions;
if $rows != 2 then
return -1
...
...
tests/script/general/parser/udf_dll_stable.sim
浏览文件 @
57f252d1
...
...
@@ -11,7 +11,7 @@ print ======================== dnode1 start
sql create function add_one as '/tmp/add_one.so' outputtype int;
sql create function add_one_64232 as '/tmp/add_one_64232.so' outputtype int;
sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype int;
sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype
big
int;
sql show functions;
if $rows != 3 then
return -1
...
...
tests/script/sh/abs_max.c
浏览文件 @
57f252d1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
typedef
struct
SUdfInit
{
int
maybe_null
;
/* 1 if function can return NULL */
int
decimals
;
/* for real functions */
long
long
length
;
/* For string functions */
int64_t
length
;
/* For string functions */
char
*
ptr
;
/* free pointer for function data */
int
const_item
;
/* 0 if result is independent of arguments */
}
SUdfInit
;
...
...
@@ -14,31 +15,36 @@ typedef struct SUdfInit{
#define TSDB_DATA_INT_NULL 0x80000000L
#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
void
abs_max
(
char
*
data
,
short
itype
,
short
ibytes
,
int
numOfRows
,
long
long
*
ts
,
char
*
dataOutput
,
char
*
interBuf
,
char
*
tsOutput
,
void
abs_max
(
char
*
data
,
short
itype
,
short
ibytes
,
int
numOfRows
,
int64_t
*
ts
,
char
*
dataOutput
,
char
*
interBuf
,
char
*
tsOutput
,
int
*
numOfOutput
,
short
otype
,
short
obytes
,
SUdfInit
*
buf
)
{
int
i
;
int
r
=
0
;
printf
(
"abs_max input data:%p, type:%d, rows:%d, ts:%p,%lld
, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p
\n
"
,
data
,
itype
,
numOfRows
,
ts
,
*
ts
,
dataOutput
,
tsOutput
,
numOfOutput
,
buf
);
int
64_t
r
=
0
;
// printf("abs_max input data:%p, type:%d, rows:%d, ts:%p, %" PRId64 "
, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
if
(
itype
==
5
)
{
r
=*
(
long
*
)
dataOutput
;
r
=*
(
int64_t
*
)
dataOutput
;
*
numOfOutput
=
0
;
for
(
i
=
0
;
i
<
numOfRows
;
++
i
)
{
if
(
*
((
long
*
)
data
+
i
)
==
TSDB_DATA_BIGINT_NULL
)
{
if
(
*
((
int64_t
*
)
data
+
i
)
==
TSDB_DATA_BIGINT_NULL
)
{
continue
;
}
*
numOfOutput
=
1
;
long
v
=
abs
(
*
((
long
*
)
data
+
i
));
//int64_t v = abs(*((int64_t *)data + i));
int64_t
v
=
*
((
int64_t
*
)
data
+
i
);
if
(
v
<
0
)
{
v
=
0
-
v
;
}
if
(
v
>
r
)
{
r
=
v
;
}
}
*
(
long
*
)
dataOutput
=
r
;
*
(
int64_t
*
)
dataOutput
=
r
;
printf
(
"abs_max out, dataoutput:%ld, numOfOutput:%d
\n
"
,
*
(
long
*
)
dataOutput
,
*
numOfOutput
);
}
else
{
// printf("abs_max out, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t
*)dataOutput, *numOfOutput);
}
else
{
*
numOfOutput
=
0
;
}
}
...
...
@@ -47,44 +53,43 @@ void abs_max(char* data, short itype, short ibytes, int numOfRows, long long* ts
void
abs_max_finalize
(
char
*
dataOutput
,
char
*
interBuf
,
int
*
numOfOutput
,
SUdfInit
*
buf
)
{
int
i
;
in
t
r
=
0
;
printf
(
"abs_max_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p
\n
"
,
dataOutput
,
*
dataOutput
,
*
numOfOutput
,
buf
);
printf
(
"abs_max finalize, dataoutput:%ld, numOfOutput:%d
\n
"
,
*
(
long
*
)
dataOutput
,
*
numOfOutput
);
//int64_
t r = 0;
//
printf("abs_max_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p\n", dataOutput, *dataOutput, *numOfOutput, buf);
// *numOfOutput=1;
// printf("abs_max finalize, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t
*)dataOutput, *numOfOutput);
}
void
abs_max_merge
(
char
*
data
,
int32_t
numOfRows
,
char
*
dataOutput
,
int32_t
*
numOfOutput
,
SUdfInit
*
buf
)
{
int
r
=
0
;
int
64_t
r
=
0
;
if
(
numOfRows
>
0
)
{
r
=
*
((
long
*
)
data
);
r
=
*
((
int64_t
*
)
data
);
}
printf
(
"abs_max_merge numOfRows:%d, dataoutput:%p, buf:%p
\n
"
,
numOfRows
,
dataOutput
,
buf
);
//
printf("abs_max_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf);
for
(
int
i
=
1
;
i
<
numOfRows
;
++
i
)
{
printf
(
"abs_max_merge %d - %ld
\n
"
,
i
,
*
((
long
*
)
data
+
i
));
if
(
*
((
long
*
)
data
+
i
)
>
r
)
{
r
=
*
((
long
*
)
data
+
i
);
// printf("abs_max_merge %d - %" PRId64"\n", i, *((int64_t
*)data + i));
if
(
*
((
int64_t
*
)
data
+
i
)
>
r
)
{
r
=
*
((
int64_t
*
)
data
+
i
);
}
}
*
(
long
*
)
dataOutput
=
r
;
*
(
int64_t
*
)
dataOutput
=
r
;
if
(
numOfRows
>
0
)
{
*
numOfOutput
=
1
;
}
else
{
*
numOfOutput
=
0
;
}
printf
(
"abs_max_merge, dataoutput:%ld, numOfOutput:%d
\n
"
,
*
(
long
*
)
dataOutput
,
*
numOfOutput
);
// printf("abs_max_merge, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t
*)dataOutput, *numOfOutput);
}
int
abs_max_init
(
SUdfInit
*
buf
)
{
printf
(
"abs_max init
\n
"
);
//
printf("abs_max init\n");
return
0
;
}
void
abs_max_destroy
(
SUdfInit
*
buf
)
{
printf
(
"abs_max destroy
\n
"
);
}
// printf("abs_max destroy\n");
}
\ No newline at end of file
tests/script/sh/add_one.c
浏览文件 @
57f252d1
...
...
@@ -14,20 +14,18 @@ void add_one(char* data, short itype, short ibytes, int numOfRows, long long* ts
int
*
numOfOutput
,
short
otype
,
short
obytes
,
SUdfInit
*
buf
)
{
int
i
;
int
r
=
0
;
printf
(
"add_one input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p
\n
"
,
data
,
itype
,
numOfRows
,
ts
,
*
ts
,
dataOutput
,
tsOutput
,
numOfOutput
,
buf
);
//
printf("add_one input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
if
(
itype
==
4
)
{
for
(
i
=
0
;
i
<
numOfRows
;
++
i
)
{
printf
(
"input %d - %d"
,
i
,
*
((
int
*
)
data
+
i
));
//
printf("input %d - %d", i, *((int *)data + i));
*
((
int
*
)
dataOutput
+
i
)
=*
((
int
*
)
data
+
i
)
+
1
;
printf
(
", output %d
\n
"
,
*
((
int
*
)
dataOutput
+
i
));
//
printf(", output %d\n", *((int *)dataOutput+i));
if
(
tsOutput
)
{
*
(
long
long
*
)
tsOutput
=
1000000
;
}
}
*
numOfOutput
=
numOfRows
;
printf
(
"add_one out, numOfOutput:%d
\n
"
,
*
numOfOutput
);
//
printf("add_one out, numOfOutput:%d\n", *numOfOutput);
}
}
}
\ No newline at end of file
tests/script/sh/add_one_64232.c
浏览文件 @
57f252d1
...
...
@@ -17,7 +17,7 @@ void add_one_64232(char* data, short itype, short ibytes, int numOfRows, long lo
printf
(
"add_one_64232 input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p
\n
"
,
data
,
itype
,
numOfRows
,
ts
,
*
ts
,
dataOutput
,
tsOutput
,
numOfOutput
,
buf
);
if
(
itype
==
5
)
{
for
(
i
=
0
;
i
<
numOfRows
;
++
i
)
{
printf
(
"input %d - %d"
,
i
,
*
((
long
*
)
data
+
i
));
printf
(
"input %d - %
l
d"
,
i
,
*
((
long
*
)
data
+
i
));
*
((
int
*
)
dataOutput
+
i
)
=
(
int
)
*
((
long
*
)
data
+
i
)
+
1
;
printf
(
", output %d
\n
"
,
*
((
int
*
)
dataOutput
+
i
));
if
(
tsOutput
)
{
...
...
@@ -28,6 +28,4 @@ void add_one_64232(char* data, short itype, short ibytes, int numOfRows, long lo
printf
(
"add_one_64232 out, numOfOutput:%d
\n
"
,
*
numOfOutput
);
}
}
}
\ No newline at end of file
tests/script/sh/sum_double.c
浏览文件 @
57f252d1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
typedef
struct
SUdfInit
{
int
maybe_null
;
/* 1 if function can return NULL */
int
decimals
;
/* for real functions */
long
long
length
;
/* For string functions */
int64_t
length
;
/* For string functions */
char
*
ptr
;
/* free pointer for function data */
int
const_item
;
/* 0 if result is independent of arguments */
}
SUdfInit
;
...
...
@@ -13,13 +14,13 @@ typedef struct SUdfInit{
#define TSDB_DATA_INT_NULL 0x80000000L
void
sum_double
(
char
*
data
,
short
itype
,
short
ibytes
,
int
numOfRows
,
long
long
*
ts
,
char
*
dataOutput
,
char
*
interBuf
,
char
*
tsOutput
,
void
sum_double
(
char
*
data
,
short
itype
,
short
ibytes
,
int
numOfRows
,
int64_t
*
ts
,
char
*
dataOutput
,
char
*
interBuf
,
char
*
tsOutput
,
int
*
numOfOutput
,
short
otype
,
short
obytes
,
SUdfInit
*
buf
)
{
int
i
;
int
r
=
0
;
printf
(
"sum_double input data:%p, type:%d, rows:%d, ts:%p,%
lld
, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p
\n
"
,
data
,
itype
,
numOfRows
,
ts
,
*
ts
,
dataOutput
,
tsOutput
,
numOfOutput
,
buf
);
int
64_t
r
=
0
;
printf
(
"sum_double input data:%p, type:%d, rows:%d, ts:%p,%
"
PRId64
"
, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p
\n
"
,
data
,
itype
,
numOfRows
,
ts
,
*
ts
,
dataOutput
,
tsOutput
,
numOfOutput
,
buf
);
if
(
itype
==
4
)
{
r
=*
(
int
*
)
dataOutput
;
r
=*
(
int
64_t
*
)
dataOutput
;
*
numOfOutput
=
0
;
for
(
i
=
0
;
i
<
numOfRows
;
++
i
)
{
...
...
@@ -29,10 +30,10 @@ void sum_double(char* data, short itype, short ibytes, int numOfRows, long long*
*
numOfOutput
=
1
;
r
+=*
((
int
*
)
data
+
i
);
*
(
int
*
)
dataOutput
=
r
;
}
*
(
int
64_t
*
)
dataOutput
=
r
;
}
printf
(
"sum_double out, dataoutput:%d, numOfOutput:%d
\n
"
,
*
(
in
t
*
)
dataOutput
,
*
numOfOutput
);
// printf("sum_double out, dataoutput:%"PRId64", numOfOutput:%d\n", *(int64_
t *)dataOutput, *numOfOutput);
}
}
...
...
@@ -40,45 +41,44 @@ void sum_double(char* data, short itype, short ibytes, int numOfRows, long long*
void
sum_double_finalize
(
char
*
dataOutput
,
char
*
interBuf
,
int
*
numOfOutput
,
SUdfInit
*
buf
)
{
int
i
;
int
r
=
0
;
printf
(
"sum_double_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p
\n
"
,
dataOutput
,
*
dataOutput
,
*
numOfOutput
,
buf
);
*
numOfOutput
=
1
;
*
(
int
*
)(
buf
->
ptr
)
=*
(
in
t
*
)
dataOutput
*
2
;
*
(
int
*
)
dataOutput
=*
(
in
t
*
)(
buf
->
ptr
);
printf
(
"sum_double finalize, dataoutput:%d, numOfOutput:%d
\n
"
,
*
(
in
t
*
)
dataOutput
,
*
numOfOutput
);
int
64_t
r
=
0
;
// printf("sum_double_finalize dataoutput:%p:%"PRId64", numOfOutput:%d, buf:%p\n", dataOutput, *(int64_t*)
dataOutput, *numOfOutput, buf);
//
*numOfOutput=1;
*
(
int
64_t
*
)(
buf
->
ptr
)
=*
(
int64_
t
*
)
dataOutput
*
2
;
*
(
int
64_t
*
)
dataOutput
=*
(
int64_
t
*
)(
buf
->
ptr
);
// printf("sum_double finalize, dataoutput:%"PRId64", numOfOutput:%d\n", *(int64_
t *)dataOutput, *numOfOutput);
}
void
sum_double_merge
(
char
*
data
,
int32_t
numOfRows
,
char
*
dataOutput
,
int
32_t
*
numOfOutput
,
SUdfInit
*
buf
)
{
void
sum_double_merge
(
char
*
data
,
int32_t
numOfRows
,
char
*
dataOutput
,
int
*
numOfOutput
,
SUdfInit
*
buf
)
{
int
r
=
0
;
int
sum
=
0
;
int
64_t
sum
=
0
;
printf
(
"sum_double_merge numOfRows:%d, dataoutput:%p, buf:%p
\n
"
,
numOfRows
,
dataOutput
,
buf
);
//
printf("sum_double_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf);
for
(
int
i
=
0
;
i
<
numOfRows
;
++
i
)
{
printf
(
"sum_double_merge %d - %d
\n
"
,
i
,
*
((
in
t
*
)
data
+
i
));
sum
+=*
((
int
*
)
data
+
i
);
// printf("sum_double_merge %d - %"PRId64"\n", i, *((int64_
t*)data + i));
sum
+=*
((
int
64_t
*
)
data
+
i
);
}
*
(
int
*
)
dataOutput
+=
sum
;
*
(
int
64_t
*
)
dataOutput
+=
sum
;
if
(
numOfRows
>
0
)
{
*
numOfOutput
=
1
;
}
else
{
*
numOfOutput
=
0
;
}
printf
(
"sum_double_merge, dataoutput:%d, numOfOutput:%d
\n
"
,
*
(
in
t
*
)
dataOutput
,
*
numOfOutput
);
// printf("sum_double_merge, dataoutput:%"PRId64", numOfOutput:%d\n", *(int64_
t *)dataOutput, *numOfOutput);
}
int
sum_double_init
(
SUdfInit
*
buf
)
{
buf
->
maybe_null
=
1
;
buf
->
ptr
=
malloc
(
sizeof
(
int
));
printf
(
"sum_double init
\n
"
);
buf
->
ptr
=
malloc
(
sizeof
(
int
64_t
));
//
printf("sum_double init\n");
return
0
;
}
void
sum_double_destroy
(
SUdfInit
*
buf
)
{
free
(
buf
->
ptr
);
printf
(
"sum_double destroy
\n
"
);
}
// printf("sum_double destroy\n");
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录