[英]Filter Flink tuples
我正在編寫一個使用Flink在Scala中進行流處理的程序。 我有一個數據流,我首先將其映射到包含json4s JValues的元組。 現在,我想基於這些JValue過濾這些元組。 我以為這很簡單,但是找不到如何通過Flink元組的列過濾的好例子。 有誰知道如何做到這一點? 謝謝
除了映射到元組,您還可以映射到案例類並過濾掉不需要的內容:
// StreamingJob.scala
...
val filteredEvents = content
.map(x => Event.toCaseClass(x))
.filter(x => x.value == true)
...
// Event.scala
case class Event(
id: String,
value: Int,
)
object Event {
implicit val formats = DefaultFormats
def toCaseClass(str: String) =
parse(str).extract[Event]
}
這個問題對我來說似乎太不確定了,但是也許不行嗎?
// stream contains stuff like these in a flink tuple
//(custom deserializer of array to tuple2???)
val jsonExample = """["foo", "bar"]"""
val stream: DataStream[Tuple2[JString, JString]] = ???
val filteredStream = stream.filter(x => x.getField(0).extract[String] == "foo")
同上,如果您正在編寫scala,最好不要使用flink元組。 去案例類或至少scala元組?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.