【发布时间】:2017-02-06 13:23:59
【问题描述】:
我执行了简单示例(spark、Windows7)并收到意外错误消息FileAlreadyExistsException。我在我的电脑上找不到文件夹或文件。
线程“main”中的异常 org.apache.hadoop.mapred.FileAlreadyExistsException:输出目录 文件:/PluralsightData/ReadMeWordCountViaApp 已存在 在 org.apache.hadoop.mapred.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:131) 在 org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1.apply$mcV$sp(PairRDDFunctions.scala:1191) 在 org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1.apply(PairRDDFunctions.scala:1168) 在 org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1.apply(PairRDDFunctions.scala:1168)
package main
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext._
object WordCounter {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Word Counter")
val sc = new SparkContext(conf)
//val textFile = sc.textFile("file:///Spark/README.md")
val textFile = sc.textFile("file:///README.md")
val tokenizedFileData = textFile.flatMap(line=>line.split(" "))
val countPrep = tokenizedFileData.map(word=>(word, 1))
val counts = countPrep.reduceByKey((accumValue, newValue)=>accumValue + newValue)
val sortedCounts = counts.sortBy(kvPair=>kvPair._2, false)
sortedCounts.saveAsTextFile("file:///PluralsightData/ReadMeWordCountViaApp")
}
}
样本来源可查询https://github.com/constructor-igor/TechSugar/tree/master/ScalaSamples/WordCounterSample
【问题讨论】:
-
嗯...正如
output directory already exists所说的那样清楚,因此您的输出saveAsTextFile将不起作用。大多数大数据框架更愿意避免覆盖任何现有数据的机会。所以......他们不允许在现有目录中输出。只需为您的输出选择其他目录。 -
如何找到
saveAsTextFile存储结果的目录并打开? -
使用像
"file:///C:/temp/WordCount这样的absolute 路径怎么样?或者查看stackoverflow.com/questions/38669206/…,了解 Spark 版本中可能存在的一些故障。 -
是的,它解决了我的问题。谢谢。
标签: windows scala apache-spark