Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3108e658
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
3108e658
编写于
12月 13, 2022
作者:
S
slzhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: expand scalar param column data to fill the udf datablock
上级
bd99fc5c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
67 addition
and
42 deletion
+67
-42
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+9
-2
tests/script/sh/compile_udf.sh
tests/script/sh/compile_udf.sh
+2
-1
tests/script/sh/gpd.c
tests/script/sh/gpd.c
+11
-39
tests/script/tsim/query/udf_with_const.sim
tests/script/tsim/query/udf_with_const.sim
+45
-0
未找到文件。
source/libs/function/src/tudf.c
浏览文件 @
3108e658
...
...
@@ -853,8 +853,15 @@ int32_t convertScalarParamToDataBlock(SScalarParam *input, int32_t numOfCols, SS
if
(
isNull
)
{
colDataAppendNNULL
(
pColInfoData
,
startRow
,
expandRows
);
}
else
{
char
*
data
=
colDataGetData
(
pColInfoData
,
(
input
+
i
)
->
numOfRows
-
1
);
colDataAppendNItems
(
pColInfoData
,
startRow
,
data
,
expandRows
);
char
*
src
=
colDataGetData
(
pColInfoData
,
(
input
+
i
)
->
numOfRows
-
1
);
int32_t
bytes
=
pColInfoData
->
info
.
bytes
;
char
*
data
=
taosMemoryMalloc
(
bytes
);
memcpy
(
data
,
src
,
bytes
);
for
(
int
j
=
0
;
j
<
expandRows
;
++
j
)
{
colDataAppend
(
pColInfoData
,
startRow
+
j
,
data
,
false
);
}
//colDataAppendNItems(pColInfoData, startRow, data, expandRows);
taosMemoryFree
(
data
);
}
}
...
...
tests/script/sh/compile_udf.sh
浏览文件 @
3108e658
set
+e
rm
-rf
/tmp/udf/libbitand.so /tmp/udf/libsqrsum.so
rm
-rf
/tmp/udf/libbitand.so /tmp/udf/libsqrsum.so
/tmp/udf/libgpd.so
mkdir
-p
/tmp/udf
echo
"compile udf bit_and and sqr_sum"
gcc
-fPIC
-shared
sh/bit_and.c
-I
../../include/libs/function/
-I
../../include/client
-I
../../include/util
-o
/tmp/udf/libbitand.so
gcc
-fPIC
-shared
sh/l2norm.c
-I
../../include/libs/function/
-I
../../include/client
-I
../../include/util
-o
/tmp/udf/libl2norm.so
gcc
-fPIC
-shared
sh/gpd.c
-I
../../include/libs/function/
-I
../../include/client
-I
../../include/util
-o
/tmp/udf/libgpd.so
echo
"debug show /tmp/udf/*.so"
ls
/tmp/udf/
*
.so
tests/script/sh/gpd.c
浏览文件 @
3108e658
...
...
@@ -12,13 +12,10 @@
TAOS
*
taos
=
NULL
;
DLL_EXPORT
int32_t
gpd_init
()
{
taos
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
""
,
7100
);
return
0
;
}
DLL_EXPORT
int32_t
gpd_destroy
()
{
taos_close
(
taos
);
taos_cleanup
();
return
0
;
}
...
...
@@ -32,43 +29,18 @@ DLL_EXPORT int32_t gpd(SUdfDataBlock* block, SUdfColumn *resultCol) {
SUdfColumnData
*
resultData
=
&
resultCol
->
colData
;
resultData
->
numOfRows
=
block
->
numOfRows
;
for
(
int32_t
i
=
0
;
i
<
resultData
->
numOfRows
;
++
i
)
{
int
j
=
0
;
for
(;
j
<
block
->
numOfCols
;
++
j
)
{
if
(
udfColDataIsNull
(
block
->
udfCols
[
j
],
i
))
{
udfColDataSetNull
(
resultCol
,
i
);
break
;
}
}
if
(
j
==
block
->
numOfCols
)
{
int32_t
luckyNum
=
88
;
udfColDataSet
(
resultCol
,
i
,
(
char
*
)
&
luckyNum
,
false
)
;
}
int
64_t
*
calc_ts
=
(
int64_t
*
)
udfColDataGetData
(
block
->
udfCols
[
0
],
i
)
;
char
*
varTbname
=
udfColDataGetData
(
block
->
udfCols
[
1
],
i
);
char
*
varDbname
=
udfColDataGetData
(
block
->
udfCols
[
2
],
i
);
char
dbName
[
256
]
=
{
0
}
;
char
tblName
[
256
]
=
{
0
};
memcpy
(
dbName
,
varDataVal
(
varDbname
),
varDataLen
(
varDbname
));
memcpy
(
tblName
,
varDataVal
(
varTbname
),
varDataLen
(
varTbname
));
printf
(
"%s, %s
\n
"
,
dbName
,
tblName
);
int32_t
result
=
0
;
udfColDataSet
(
resultCol
,
i
,
(
char
*
)
&
result
,
false
);
}
TAOS_RES
*
res
=
taos_query
(
taos
,
"create database if not exists gpd"
);
if
(
taos_errno
(
res
)
!=
0
)
{
char
*
errstr
=
taos_errstr
(
res
);
}
res
=
taos_query
(
taos
,
"create table gpd.st (ts timestamp, f int) tags(t int)"
);
if
(
taos_errno
(
res
)
!=
0
)
{
char
*
errstr
=
taos_errstr
(
res
);
}
taos_query
(
taos
,
"insert into gpd.t using gpd.st tags(1) values(now, 1) "
);
if
(
taos_errno
(
res
)
!=
0
)
{
char
*
errstr
=
taos_errstr
(
res
);
}
taos_query
(
taos
,
"select * from gpd.t"
);
if
(
taos_errno
(
res
)
!=
0
)
{
char
*
errstr
=
taos_errstr
(
res
);
}
//to simulate actual processing delay by udf
#ifdef LINUX
usleep
(
1
*
1000
);
// usleep takes sleep time in us (1 millionth of a second)
#endif
#ifdef WINDOWS
Sleep
(
1
);
#endif
return
0
;
}
tests/script/tsim/query/udf_with_const.sim
0 → 100644
浏览文件 @
3108e658
system_content printf %OS%
if $system_content == Windows_NT then
return 0;
endi
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c udf -v 1
system sh/exec.sh -n dnode1 -s start
sql connect
print ======== step1 udf
system sh/compile_udf.sh
sql create database udf vgroups 3;
sql use udf;
sql create table t (ts timestamp, f int);
sql insert into t values(now, 1)(now+1s, 2)(now+2s,3)(now+3s,4)(now+4s,5)(now+5s,6)(now+6s,7);
system_content printf %OS%
if $system_content == Windows_NT then
return 0;
endi
if $system_content == Windows_NT then
sql create function gpd as 'C:\\Windows\\Temp\\gpd.dll' outputtype int bufSize 8;
else
sql create function gpd as '/tmp/udf/libgpd.so' outputtype int bufSize 8;
endi
sql show functions;
if $rows != 1 then
return -1
endi
sql select gpd(ts, tbname, 'detail') from t;
if $rows != 7 then
return -1
endi
print $data00 $data10
if $data00 != @0@ then
return -1
endi
sql drop function gpd;
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录