res=driver.query(conn,"CREATE TABLE therm1 USING thermometer TAGS ('beijing', 1)")
res=driver.query(conn,"create table therm1 using thermometer tags ('beijing', 1)")
ifres.code~=0then
ifres.code~=0then
print(res.error)
print(res.error)
return
return
...
@@ -86,7 +134,7 @@ else
...
@@ -86,7 +134,7 @@ else
print("create table--- pass")
print("create table--- pass")
end
end
res=driver.query(conn,"INSERT INTO therm1 VALUES ('2019-09-01 00:00:00.001', 20),('2019-09-01 00:00:00.002', 21)")
res=driver.query(conn,"insert into therm1 values ('2019-09-01 00:00:00.001', 20),('2019-09-01 00:00:00.002', 21)")
ifres.code~=0then
ifres.code~=0then
print(res.error)
print(res.error)
...
@@ -99,14 +147,14 @@ else
...
@@ -99,14 +147,14 @@ else
end
end
end
end
res=driver.query(conn,"SELECT COUNT(*) count, AVG(degree) AS av, MAX(degree), MIN(degree) FROM thermometer WHERE location='beijing' or location='tianjin' GROUP BY location, type")
res=driver.query(conn,"select count(*) as cnt, avg(degree) as av, max(degree), min(degree) from thermometer where location='beijing' or location='tianjin' group by location, type")
ifres.code~=0then
ifres.code~=0then
print("select from super table--- failed:"..res.error)
print("select from super table--- failed:"..res.error)
return
return
else
else
print("select from super table--- pass")
print("select from super table--- pass")
fori=1,#(res.item)do
fori=1,#(res.item)do
print("res:"..res.item[i].count)
print("res:"..res.item[i].cnt)
end
end
end
end
...
@@ -125,33 +173,16 @@ function async_query_callback(res)
...
@@ -125,33 +173,16 @@ function async_query_callback(res)
res=driver.query(conn,"create stream stream_avg_degree into avg_degree as select avg(degree) from thermometer interval(5s) sliding(1s)")
print("------------------------")
print("continuous query result:")
forkey,valueinpairs(t)do
print("key:"..key..", value:"..value)
end
end
localstream
print("From now on we start continous insertion in an definite (infinite if you want) loop.")
res=driver.open_stream(conn,"SELECT COUNT(*) as count, AVG(degree) as avg, MAX(degree) as max, MIN(degree) as min FROM thermometer interval(2s) sliding(2s);)",0,stream_callback)
ifres.code~=0then
print("open stream--- failed:"..res.error)
return
else
print("open stream--- pass")
stream=res.stream
end
print("From now on we start continous insert in an definite (infinite if you want) loop.")
localloop_index=0
localloop_index=0
whileloop_index<30do
whileloop_index<30do
localt=os.time()*1000
localt=os.time()*1000
localv=loop_index
localv=loop_index
res=driver.query(conn,string.format("INSERT INTO therm1 VALUES (%d, %d)",t,v))
res=driver.query(conn,string.format("insert into therm1 values (%d, %d)",t,v))