Remove error about stream in lua test case. (#16990)
This commit is contained in:
parent
9595412159
commit
16be3ca310
Binary file not shown.
|
@ -1,11 +1,11 @@
|
|||
#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);
|
||||
|
|
|
@ -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 insertion 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 < 30 do
|
||||
while loop_index < 10 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)
|
||||
|
|
Loading…
Reference in New Issue