我想处理以下 JSON 对象:
[
{
id: "38485ndndndn4848",
value : 120, // kw
ts: 1456983266,
sensor_id: 20
},
{
id: "48485ndndndn4848",
value : 189, //kw
ts: 1456984286,
sensor_id: 20
},
{
id: "98485ndndndn4848",
value : 99, // kw
ts: 1457984286,
sensor_id: 21
},
{
id: "64640485ndndndn4848",
value : 56, // kw
ts: 1458984286,
sensor_id: 21
}
.
.
.
]
为了获得以千瓦时为单位的每个传感器的每日消耗量。到目前为止,我已经创建了以下 Java 类:
public class Tick {
String id;
Integer sensorId;
Double value;
Date ts;
public Tick(JSONObject obj) {
this.id = (String) obj.get('id');
long timestamp = (Long) obj.get("ts");
this.ts = new Date(timestamp * 1000);
this.value = (Double)message.get("value");
}
使用此 epl 查询:
EPStatement cepStatement = cepAdm.createEPL("select max(ts) as date, sensorId from " +
"StockTick() group by deviceId ");
EPStatement cepStatement3 = cepAdm.createEPL("insert into Consumption" +
"select t0.ts, sum(t0.value*(t1.ts-t0.ts)/3600) as val , sensorId from StockTick() as t0 join StockTick() as t1 on t0.sensorId=t1.sensorId group by ts.getYear(), ts.getMonthOfYear(), ts.getDayOfMonth() , sensorId ");
- -更新 - - - - - - -
EPStatement cepStatement3 = cepAdm.createEPL("insert into DailyConsumption " +
"select t0.sync, sum( t0.value * ( t1.ts - t0.ts ) / 3600) as val , t0.sensorId from StockTick().win:length(2) "+
"as t0 join StockTick().win:length(2) as t1 on t1.sensorId = t0.sensorId "+
"where t1.id != t0.id and t1.ts > t0.ts"+
"group by sync.getYear(), sync.getMonthOfYear(), sync.getDayOfMonth() , deviceId");
它产生以下错误:
Incorrect syntax near 'by' (a reserved keyword) at line 1 column 261 [insert into DailyConsumption select