为什么不能在DolphinDB的DFS表中插入记录

时间:2019-10-31 14:00:04

标签: sql database distributed-system dolphindb

我的代码如下,

login("admin","123456")
share streamTable(1000000:0,`deviceID`ts`batteryTemperature`cpuPercentage`mem_free,[INT,TIMESTAMP,DOUBLE,DOUBLE,DOUBLE]) as sensor_readings
enableTablePersistence(sensor_readings, true, false, 1000000)

if(exists("dfs://iotDemoDB")){
  dropDatabase("dfs://iotDemoDB")
}
tableSchema = table(1000000:0,`deviceID`ts`batteryTemperature`cpuPercentage`mem_free,[INT,TIMESTAMP,DOUBLE,DOUBLE,DOUBLE])
db1 = database("",VALUE,2019.04.24..2019.05.20) 
db2 = database("",RANGE,0..10*100)
db = database("dfs://iotDemoDB",COMPO,[db1,db2])
dfsTable = db.createPartitionedTable(tableSchema,"sensor_readings",`ts`deviceID)

subscribeTable(, "sensor_readings", "save_to_db", -1, append!{dfsTable}, true, 1000,1)

share streamTable(1000000:0, `time`deviceID`batteryTemperature_avg`cpuPercentage_avg`mem_free_avg, [TIMESTAMP,INT,DOUBLE,DOUBLE,DOUBLE]) as sensor_readings_avg
metrics = createTimeSeriesAggregator("aggr1",60000,2000,<[avg(batteryTemperature),avg(cpuPercentage),avg(mem_free)]>,sensor_readings,sensor_readings_avg,`ts,,`deviceID,2000) 
subscribeTable(, "sensor_readings", "metric_engine", -1, append!{metrics},true)

 //write data to stream table
 def writeData(){
     deviceNum = 1000
     for (i in 0:100000) {
     data = table(take(1..deviceNum,deviceNum) as deviceID ,take(now(),deviceNum) as ts,rand(70..102,deviceNum) as batteryTemperature,rand(15..80,deviceNum) as cpuPercentage,rand(1..32,deviceNum) as mem_free)
      sensor_readings.append!(data)
      sleep(10000)
   }
}
jobId = submitJob("simulateData", "simulate sensor data", writeData)

在DolphinDB GUI中执行代码,我使用以下代码显示表的记录,

select gmtime(time) as time, batteryTemperature_avg,cpuPercentage_avg,mem_free_avg from sensor_readings_avg where deviceID = 1

我可以看到表中有记录。但是我查询了DFS表,

dfsTable=loadTable("dfs://iotDemoDB","sensor_readings")
select count(*) from dfsTable

表中没有记录。你知道为什么吗?谢谢。

0 个答案:

没有答案