gpt4 book ai didi

scala - Flink 无法序列化 Scala 类/任务不可序列化

转载 作者:行者123 更新时间:2023-12-04 11:48:57 27 4
gpt4 key购买 nike

我的 scala 类有 2 个字段,它们是 vals 但 flink 说它没有 setter。因此任务不可序列化。

我尝试使用 var setter ,但它说重复 setter 。 vals 是公开的,那么为什么它要求 setter 。 Flink 版本 1.1.0

class Impression(val map: Map[String, String],val keySet:Set[String])

我的代码:

  val preAggregate = stream
.filter(impression => {
true
})
.map(impression => {
val xmap = impression.map
val values = valFunction(xmap)
new ImpressionRecord(impression, values._1, values._2, values._3)
})

异常(exception)情况:

**class Impression does not contain a setter for field map**
19:54:49.995 [main] INFO o.a.f.a.java.typeutils.TypeExtractor - class Impression is not a valid POJO type
19:54:49.997 [main] DEBUG o.a.flink.api.scala.ClosureCleaner$ - accessedFields: Map(class -> Set())
Exception in thread "main" **org.apache.flink.api.common.InvalidProgramException: Task not serializable
at** org.apache.flink.api.scala.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:172)
at )
Caused by: java.io.NotSerializableException: org.apache.flink.streaming.api.scala.DataStream
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at org.apache.flink.util.InstantiationUtil.serializeObject(InstantiationUtil.java:301)
at org.apache.flink.api.scala.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:170)
... 18 more

最佳答案

尽量不要直接使用类的字段,而是将其包装在一个方法中,这样就可以了。

关于scala - Flink 无法序列化 Scala 类/任务不可序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38832055/

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