【发布时间】:2016-05-09 10:14:34
【问题描述】:
这有效(df:数据框)
val filteredRdd = df.rdd.zipWithIndex.collect { case (r, i) if i >= 10 => r }
这不是
val start=10
val filteredRdd = df.rdd.zipWithIndex.collect { case (r, i) if i >= start => r }
我尝试使用广播变量,但即使这样也没有用
val start=sc.broadcast(1)
val filteredRdd = df.rdd.zipWithIndex.collect { case (r, i) if i >= start.value => r }
我收到 Task Not Serializable 异常。任何人都可以解释为什么即使使用广播变量它也会失败。
org.apache.spark.SparkException: Task not serializable
at org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:304)
at org.apache.spark.util.ClosureCleaner$.org$apache$spark$util$ClosureCleaner$$clean(ClosureCleaner.scala:294)
at org.apache.spark.util.ClosureCleaner$.clean(ClosureCleaner.scala:122)
at org.apache.spark.SparkContext.clean(SparkContext.scala:2055)
at org.apache.spark.rdd.RDD$$anonfun$collect$2.apply(RDD.scala:959)
at org.apache.spark.rdd.RDD$$anonfun$collect$2.apply(RDD.scala:958)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:111)
at org.apache.spark.rdd.RDD.withScope(RDD.scala:316)
at org.apache.spark.rdd.RDD.collect(RDD.scala:958)
at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$$$$$fa17825793f04f8d2edd8765c45e2a6c$$$$wC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.(:172)
at $iwC
【问题讨论】:
-
如果
start是某些(不可序列化)类的一部分,这可能会发生 - 是吗?您能否提供更详细的代码示例? -
我在 zipwithIndex 操作之前定义了
start。我没有课。这是一个脚本,直接编写用于解释。
标签: scala apache-spark spark-dataframe