答案 0 :(得分:0)
我有一个解决方法。
根据document,元素将在CEP中缓冲以等待水印。
所以我决定改变水印生成策略,如下所示。
public class UnionStreamTimestampExtractor implements AssignerWithPeriodicWatermarks<JSONObject> {
private long currentMaxTimestamp;
private boolean hasAlgoRule;
public UnionStreamTimestampExtractor(boolean hasAlgoRule) {
this.hasAlgoRule = hasAlgoRule;
}
@Nullable
@Override
public Watermark getCurrentWatermark() {
return new Watermark(currentMaxTimestamp);
}
@Override
public long extractTimestamp(JSONObject element, long previousElementTimestamp) {
long timestamp = element.get("occur_time") == null ?
element.getLong("timestamp") : element.getLong("occur_time");
// if this entity has algorithm rule
// let anomaly slice generate watermark, so that CEP can buffer raw log data to wait them.
if (hasAlgoRule) {
if (element.containsKey("tensor")) {
currentMaxTimestamp = Math.max(timestamp, currentMaxTimestamp);
}
} else {
currentMaxTimestamp = Math.max(timestamp, currentMaxTimestamp);
}
return timestamp;
}
}
但是它仍然存在问题,如果流的速度非常不同,则元素将会很多。