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
ifres.code~=0then
print("select error:"..res.error)
print("select from super table--- failed:"..res.error)
return
return
else
else
print("in lua, result:")
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].count)
end
end
end
end
functioncallback(t)
functioncallback(t)
print("------------------------")
print("continuous query result:")
print("continuous query result:")
forkey,valueinpairs(t)do
forkey,valueinpairs(t)do
print("key:"..key..", value:"..value)
print("key:"..key..", value:"..value)
...
@@ -97,25 +121,25 @@ end
...
@@ -97,25 +121,25 @@ end
localstream
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)
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
ifres.code~=0then
print("open stream error:"..res.error)
print("open stream--- failed:"..res.error)
return
return
else
else
print("openstream ok")
print("open stream--- pass")
stream=res.stream
stream=res.stream
end
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
localloop_index=0
whileloop_index<10do
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))