Scala 即使使用POJO,任务也不能在Flink中序列化

Scala 即使使用POJO,任务也不能在Flink中序列化,scala,serialization,apache-flink,pojo,Scala,Serialization,Apache Flink,Pojo,我有一个从CSV文件读取的数据集: val dataSet = env.readCsvFile[ElecNormNew]( getClass.getResource("/elecNormNew.arff").getPath, pojoFields = Array("date", "day", "period", "nswprice", "nswdemand", "vicprice", "vicdemand", "transfer", "label") 据我所知,Elec

我有一个从CSV文件读取的
数据集

val dataSet = env.readCsvFile[ElecNormNew](
      getClass.getResource("/elecNormNew.arff").getPath,
      pojoFields = Array("date", "day", "period", "nswprice", "nswdemand", "vicprice", "vicdemand", "transfer", "label")
据我所知,
ElecNormNew
是一个POJO:

// elecNormNew POJO
class ElecNormNew(
  var date: Double,
  var day: Int,
  var period: Double,
  var nswprice: Double,
  var nswdemand: Double,
  var vicprice: Double,
  var vicdemand: Double,
  var transfer: Double,
  var label: String) extends Serializable {

  def this() = {
    this(0, 0, 0, 0, 0, 0, 0, 0, "")
  }
}
我还有一个简单的类:

case class Discretizer[T](
  data: DataSet[T],
  nBins: Int = 5,
  s: Int = 1000) {

  private[this] val log = LoggerFactory.getLogger("Discretizer")
  private[this] val V = Vector.tabulate(10)(_ => IntervalHeap(nBins, 1, 1, s))

  private[this] def updateSamples(x: T): Vector[IntervalHeap] = {
    log.warn(s"$x")
    V
  }

  def discretize() = {
    data map (x => updateSamples(x))
  }
}
但当我尝试使用它时,例如从测试中:

val a = new Discretizer[ElecNormNew](dataSet)
a.discretize
我得到以下错误:

org.apache.flink.api.common.InvalidProgramException: Task not serializable
// ...
[info]     at com.elbauldelprogramador.discretizers.IDADiscretizer.discretize(IDADiscretizer.scala:69)
// ...
[info]     Cause: java.io.NotSerializableException: org.apache.flink.api.scala.DataSet
// ...
我读过这些问题及其答案,但运气不好:


我想说你提到的第一个链接:

问题是您从MapFunction中引用数据集页面。这是不可能的,因为数据集只是数据流的逻辑表示,不能在运行时访问


离散化
使用
映射
,因此这也适用于此处

但是如果我理解正确,问题是当您在map函数中引用数据集时,在这种情况下,
Pages
,但我为函数提供的是一个数据点,而不是
DataSet[T]
本身。@elbaulp但是您仍然会遇到同样的错误,所以在将map应用到它之前,请尝试使用另一个类来表示数据。