The problem is this:
val isNegative = (num: Int) => num < 0
is just syntactic sugar for this:
val isNegative = new Function1[Int, Boolean] {
def apply(num: Int): Boolean = num < 0
}
Function1is a sign, and an anonymous function is not serializable. When you have something like this:
object Tests {
def isNegative(num: Int): Boolean = num < 0
}
Now isNegativeis a member Teststhat is serializable. When you call this:
val dataset = CreateRDD(data.filter(isNegative))
isNegative node. , , def, , , val, Spark isNegative, .