简体   繁体   中英

Why saveAsTextFile do nothing?

I'm trying to implement simple WordCount in Scala + Spark. Here is my code

object FirstObject {
  def main(args: Array[String]) {
    val input = "/Data/input"
    val conf = new SparkConf().setAppName("Simple Application")
                              .setMaster("spark://192.168.1.162:7077")
    val sparkContext = new SparkContext(conf)
    val text = sparkContext.textFile(input).cache()
    val wordCounts = text.flatMap(line => line.split(" "))
                         .map(word => (word,1))
                         .reduceByKey((a,b) => a+b)
                         .sortByKey()
    wordCounts.saveAsTextFile("/Data/output")

  }

This job is working for 54s , and finally do nothing. Is is not writing output to /Data/output

Also if I replace saveAsTextFile with forEach(println) it is produce desired output.

You should check your user rights for /data/output folder. This folder should have writing rights for your specific user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM