【发布时间】:2017-02-22 04:21:55
【问题描述】:
我有以下火花简单的例子:
#1 val lines: RDD[String] = sc.textFile("/data/non_existing_file.txt")
#2 val words: RDD[String] = lines.flatMap(line => line.split(" "))
#3 val pairs: RDD[(String, Int)] = words.map(word => (word, 1))
#4 val counts: RDD[(String, Int)] = pairs.reduceByKey(_ + _)
#5 counts.saveAsTextFile("/tmp/result")
当我运行程序时,我得到了一个异常 Input path does not exist: file:/data/non_existing_file.txt",正如预期的那样。
公认的是我在第 4 行得到了这个异常。我知道我在第 1 行、第 2 行和第 3 行中没有收到此错误,因为尚未执行计算。 当我有将结果写入文件的操作时,计算仅在第 5 行执行。那么,为什么我在第 4 行而不是第 5 行出现异常?
【问题讨论】:
标签: apache-spark rdd