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 error:"..res.error)
print("select from super table--- failed:"..res.error)
return
else
print("in lua, result:")
print("select from super table--- pass")
fori=1,#(res.item)do
print("res:"..res.item[i].count)
end
end
functioncallback(t)
print("------------------------")
print("continuous query result:")
forkey,valueinpairs(t)do
print("key:"..key..", value:"..value)
...
...
@@ -97,25 +121,25 @@ end
localstream
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,callback)
ifres.code~=0then
print("open stream error:"..res.error)
print("open stream--- failed:"..res.error)
return
else
print("openstream ok")
print("open stream--- pass")
stream=res.stream
end
--From now on we begin continous query in an definite (infinite if you want) loop.
print("From now on we start continous insert in an definite (infinite if you want) loop.")
localloop_index=0
whileloop_index<10do
whileloop_index<30do
localt=os.time()*1000
localv=loop_index
res=driver.query(conn,string.format("INSERT INTO therm1 VALUES (%d, %d)",t,v))