Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
16be3ca3
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看板
未验证
提交
16be3ca3
编写于
9月 21, 2022
作者:
R
robotspace
提交者:
GitHub
9月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove error about stream in lua test case. (#16990)
上级
95954121
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
9 addition
and
85 deletion
+9
-85
examples/lua/OpenResty/so/luaconnector51.so
examples/lua/OpenResty/so/luaconnector51.so
+0
-0
examples/lua/lua51/lua_connector51.c
examples/lua/lua51/lua_connector51.c
+3
-70
examples/lua/test.lua
examples/lua/test.lua
+6
-15
未找到文件。
examples/lua/OpenResty/so/luaconnector51.so
浏览文件 @
16be3ca3
无法预览此类型文件
examples/lua/lua51/lua_connector51.c
浏览文件 @
16be3ca3
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "
lua
.h"
#include "
taos
.h"
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
#include <taos.h>
struct
cb_param
{
lua_State
*
state
;
...
...
@@ -60,7 +60,6 @@ static int l_connect(lua_State *L){
lua_settop
(
L
,
0
);
taos_init
();
lua_newtable
(
L
);
int
table_index
=
lua_gettop
(
L
);
...
...
@@ -137,19 +136,15 @@ static int l_query(lua_State *L){
lua_pushstring
(
L
,
fields
[
i
].
name
);
int32_t
*
length
=
taos_fetch_lengths
(
result
);
switch
(
fields
[
i
].
type
)
{
case
TSDB_DATA_TYPE_UTINYINT
:
case
TSDB_DATA_TYPE_TINYINT
:
lua_pushinteger
(
L
,
*
((
char
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
lua_pushinteger
(
L
,
*
((
short
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_INT
:
lua_pushinteger
(
L
,
*
((
int
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_BIGINT
:
lua_pushinteger
(
L
,
*
((
int64_t
*
)
row
[
i
]));
break
;
...
...
@@ -159,7 +154,6 @@ static int l_query(lua_State *L){
case
TSDB_DATA_TYPE_DOUBLE
:
lua_pushnumber
(
L
,
*
((
double
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
//printf("type:%d, max len:%d, current len:%d\n",fields[i].type, fields[i].bytes, length[i]);
...
...
@@ -241,67 +235,6 @@ static int l_async_query(lua_State *L){
return
1
;
}
void
stream_cb
(
void
*
param
,
TAOS_RES
*
result
,
TAOS_ROW
row
){
struct
cb_param
*
p
=
(
struct
cb_param
*
)
param
;
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
int
numFields
=
taos_num_fields
(
result
);
// printf("\nnumfields:%d\n", numFields);
//printf("\n\r-----------------------------------------------------------------------------------\n");
lua_State
*
L
=
p
->
state
;
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
p
->
callback
);
lua_newtable
(
L
);
for
(
int
i
=
0
;
i
<
numFields
;
++
i
)
{
if
(
row
[
i
]
==
NULL
)
{
continue
;
}
lua_pushstring
(
L
,
fields
[
i
].
name
);
switch
(
fields
[
i
].
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
lua_pushinteger
(
L
,
*
((
char
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
lua_pushinteger
(
L
,
*
((
short
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_INT
:
lua_pushinteger
(
L
,
*
((
int
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_BIGINT
:
lua_pushinteger
(
L
,
*
((
int64_t
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_FLOAT
:
lua_pushnumber
(
L
,
*
((
float
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
lua_pushnumber
(
L
,
*
((
double
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
lua_pushstring
(
L
,(
char
*
)
row
[
i
]);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
lua_pushinteger
(
L
,
*
((
int64_t
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_BOOL
:
lua_pushinteger
(
L
,
*
((
char
*
)
row
[
i
]));
break
;
default:
lua_pushnil
(
L
);
break
;
}
lua_settable
(
L
,
-
3
);
}
lua_call
(
L
,
1
,
0
);
// printf("-----------------------------------------------------------------------------------\n\r");
}
static
int
l_close
(
lua_State
*
L
){
TAOS
*
taos
=
(
TAOS
*
)
lua_topointer
(
L
,
1
);
...
...
examples/lua/test.lua
浏览文件 @
16be3ca3
...
...
@@ -173,16 +173,16 @@ function async_query_callback(res)
end
end
driver
.
query_a
(
conn
,
"
insert into therm1 values
('2019-09-01 00:00:00.005', 100),('2019-09-01 00:00:00.006', 101),('2019-09-01 00:00:00.007', 102)"
,
async_query_callback
)
driver
.
query_a
(
conn
,
"
INSERT INTO therm1 VALUES
('2019-09-01 00:00:00.005', 100),('2019-09-01 00:00:00.006', 101),('2019-09-01 00:00:00.007', 102)"
,
async_query_callback
)
res
=
driver
.
query
(
conn
,
"create stream stream_avg_degree into avg_degree as select avg(degree) from thermometer interval(5s) sliding(1s)"
)
print
(
"From now on we start continous insert
ion in an definite (infinite if you want) loop
."
)
print
(
"From now on we start continous insert
in an definite loop, pls wait for about 10 seconds and check stream table for result
."
)
local
loop_index
=
0
while
loop_index
<
3
0
do
while
loop_index
<
1
0
do
local
t
=
os.time
()
*
1000
local
v
=
loop_index
res
=
driver
.
query
(
conn
,
string.format
(
"
insert into therm1 values
(%d, %d)"
,
t
,
v
))
local
v
=
math.random
(
20
)
res
=
driver
.
query
(
conn
,
string.format
(
"
INSERT INTO therm1 VALUES
(%d, %d)"
,
t
,
v
))
if
res
.
code
~=
0
then
print
(
"continous insertion--- failed:"
..
res
.
error
)
...
...
@@ -190,17 +190,8 @@ while loop_index < 30 do
else
--print("insert successfully, affected:"..res.affected)
end
local
res1
=
driver
.
query
(
conn
,
string.format
(
"select last(*) from avg_degree"
))
if
res1
.
code
~=
0
then
print
(
"select failed: "
..
res1
.
error
)
return
else
-- print(dump(res1))
if
(
#
res1
.
item
>
0
)
then
print
(
"avg_degree: "
..
res1
.
item
[
1
][
"last(avg(degree))"
])
end
end
os.execute
(
"sleep "
..
1
)
loop_index
=
loop_index
+
1
end
driver
.
query
(
conn
,
"DROP STREAM IF EXISTS avg_therm_s"
)
driver
.
close
(
conn
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录