Pedro Alves Pedro Alves - 1 month ago 16
Scala Question

error: value saveAsTextFile is not a member of Unit - Spark

I'm trying to save the results into a text file using:

results.collect().foreach { rule => println("[" + rule.antecedent.mkString(",") + "=>" + rule.consequent.mkString(",") + "]," + rule.confidence)}.saveAsTextFile("/user/cloudera/rules")


But I got this error:

<console>:43: error: value saveAsTextFile is not a member of Unit
results.collect().foreach { rule => println("[" + rule.antecedent.mkString(",") + "=>" + rule.consequent.mkString(",") + "]," + rule.confidence)}.saveAsTextFile("/user/cloudera/rules")


What I need to change? I don't understand the error...

Answer

If you want to save use:

results.map { rule => 
     "[" + rule.antecedent.mkString(",") + "=>" + rule.consequent.mkString(",") + "]," + rule.confidence
}.saveAsTextFile("/user/cloudera/rules")
Comments