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
print(res.error)
return
...
...
@@ -90,7 +134,7 @@ else
print("create table--- pass")
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
print(res.error)
...
...
@@ -103,7 +147,7 @@ else
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(*) count, avg(degree) as av, max(degree), min(degree) from thermometer where location='beijing' or location='tianjin' group by location, type")
ifres.code~=0then
print("select from super table--- failed:"..res.error)
return
...
...
@@ -129,33 +173,16 @@ function async_query_callback(res)
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
res=driver.query(conn,"create table avg_degree as select avg(degree) from thermometer where ts > now and ts <= now + 1m interval(5s) sliding(1s)")
print("From now on we start continous insert in an definite (infinite if you want) loop.")
print("From now on we start continous insertion in an definite (infinite if you want) loop.")
localloop_index=0
whileloop_index<30do
localt=os.time()*1000
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))