apache flink+cep-检测相同的事件

smtd7mpg  于 2021-06-25  发布在  Flink
关注(0)|答案(1)|浏览(467)

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

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)
cedebl8k

cedebl8k1#

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

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()

相关问题