2016-04-08 138 views
3

没有有效的构造这是我的代码:的火花

class FNNode(val name: String) 

case class Ingredient(override val name: String, category: String) extends FNNode(name) 


val ingredients: RDD[(VertexId, FNNode)] = 
sc.textFile(PATH+"ingr_info.tsv"). 
     filter(! _.startsWith("#")). 
     map(line => line.split('\t')). 
     map(x => (x(0).toInt ,Ingredient(x(1), x(2)))) 

而且有当我定义这些变量没有错误。然而,当试图执行它:

ingredients.take(1) 

我得到

org.apache.spark.SparkException: Job aborted due to stage failure: Exception while getting task result: java.io.InvalidClassException: $iwC$$iwC$Ingredient; no valid constructor 
    at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1431) 
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1419) 

看来,这可能是每答案here涉及到序列化的问题。但是,如果这确实是一个序列化问题,我不知道如何解决这个问题。

我沿着this书中的代码按照他们的方式,所以我会认为这应该至少在某个时间点工作?

+0

FNNode必须有一个案例类以及除非我想。 – eliasah

+0

不幸的是,我得到这个:“error:case class Ingredient has case ancestor $ iwC。$ iwC.FNNode,但是case-to-case inheritance is prohibited。为了克服这个限制,使用提取器在非叶节点上模式匹配” – elelias

+1

你可以试试,是否有助于让FNNode扩展Serializable? –

回答

5

这个固定您的问题对我来说:

class FNNode(val name: String) extends Serializable 
+0

工作,非常感谢。 – elelias