gpt4 book ai didi

java - Apache Flink + CEP - 检测相同事件

转载 作者:行者123 更新时间:2023-11-30 07:13:44 24 4
gpt4 key购买 nike

我想检测共享相同属性的事件。假设我有一个简单的案例类:

case class Record(name: String, value: Int)

假设有以下流:

Record("A", 1)
Record("B", 2)
Record("A", 3)
Record("C", 4)

然后我想检测双“A”记录。这可能吗?我现在有这个:

val start: Pattern[Record, _] = myStream
.begin("first")
.followedBy("second").where(previous_record.name == _.name)

最佳答案

我认为您正在定义什么是事件检测,您是否尝试过:

val start: Pattern[Record, _] = myStream
.begin("first").where(name == "A")
.followedBy("second").where(name == "A")

更新:例如:

val patternIG: Pattern[(String,String), _] = Pattern.begin[String,String)]("start").where(_.name == "Ignition").where(_.ac == "ON").next("end").where(_.name == "Door").where(_.ac == "ON")
val patternStream: PatternStream[(String,String)] = CEP.pattern(mystream, patternIG)
def selectFn(pattern : mutable.Map[String,(String,String)]): String = {
val startEvent = pattern.get("start").get
val endEvent = pattern.get("end").get
"ALERT Door Open"
}
val patternStreamSelected = patternStream.select(selectFn(_)).print()

关于java - Apache Flink + CEP - 检测相同事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38770195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com