[英]Esper EPL aggregation with custom function
我正在嘗試使用以下代碼對 Esper 8.8.0 EPL 進行聚合。 當 ProductEvent 發布時,我試圖在將完整的 ProductEvent bean object 轉換為 json 后將其保存到表中。有什么方法可以在執行合並語句時在自定義 function 中傳遞 ProductEven Object 本身 -
@public create table OutputTable
(
productId string primary key
, productName string
, productJson string
);
@name('stmtUpdateOutputTable') on ProductEvent pe
merge OutputTable ot
where ot.productId = pe.productId
when not matched
then insert select productId, productName, Utils.getJson(*)
when matched
then update
set
ot.productName= pe.productName,
ot.productJson = Utils.getJson(*)
;
ProductEvent 是一個包含 100 多個屬性的 java bean,所以在調用自定義 function 時傳遞每個單獨的字段不是一個好主意 -
public class ProductEvent{
private String productId;
private String productName;
private Double price;
private LocalDate firstAvailableDate;
//..... around 100 more properties here
}
Utils 是一個 helper class 包含 static 方法 -
public static String getJson(ProductEvent event) {
return new ObjectMapper().writeValueAsString(event);
}
在合並時,有兩個別名:ProductEvent 的“pe”和 OutputTable 的“ot”,因此“ ...Utils.getJson(pe)...
”會起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.