Esper Java EPL模式

时间:2017-01-17 11:07:21

标签: java json esper epl

我想处理以下JSON对象:

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");

  }

为了获得每个传感器的 DAILY 消耗,单位为kWh。 到目前为止,我已经创建了以下Java类:

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 ");

使用此epl查询:

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 

它会产生以下错误:

export function saveUser(user){
  return function(dispatch){

    fetch(`${data.ROOT_URL}/save-user/`, {
        method: 'post',
        // body: How???
    })
        .then(response => {

            if (response.status !== 200) {
                console.log('Looks like there was a problem. Status Code: ' + response.status);
                return;
            }

            console.log('You are successfully registered!: ' + response.status);
        })

        .catch(function (error) {
            console.log(error);
        });
  }
}

0 个答案:

没有答案