希望有人能提供帮助。
我试图传输一些数据,并将物联网设备的当前状态保持为Kudu。
我目前正在使用ForeachWriter作为接收器 - 遗憾的是,它仅在有一行时有效,如果有多行挂起并且没有将任何数据写入Kudu表
有没有人见过这个?
代码:
df.select("...DATA....." )
.as[IoTState]
.groupByKey(_.assetId)
.mapGroupsWithState(GroupStateTimeout.NoTimeout)(updateIoTState)
.writeStream
.foreach(new ForeachWriter[IoTState]
{
override def open(partitionId: Long, version: Long): Boolean = {
true
}
override def process(value: IoTState): Unit = {
val valueDF: DataFrame = Seq(value).toDF(
"assetId"
, "eventDateTimeInUTC"
, "gpsLatitudeInDegrees"
, "gpsLongitudeInDegrees"
)
kuduContext1.upsertRows(valueDF, conf.kuduTable)
}
override def close(errorOrNull: Throwable): Unit = {
}
})
.outputMode("update")
.trigger(Trigger.ProcessingTime("2 seconds"))
.start()
.awaitTermination()