2016-12-16 132 views
1

我的機器是windows機器。我正在eclipse IDE中測試我的spark代碼。在Spark中讀取windows網絡文件

我有我的文件sample.txt存儲在網絡文件夾。

文件的位置屬性是\\\aloha\logfolder

我想在sparkcontext中讀取它。以下是我的代碼片段。

val conf = new SparkConf().setAppName("WordCount").setMaster("local") 
val sc = new SparkContext(conf) 
val inp = sc.textFile("\\\\aloha\\logfolder\\sample.txt") 

但我得到了以下錯誤:

Exception in thread "main" org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: file://aloha/logfolder/sample.txt 

我曾嘗試以下選項,以及。

val inp = sc.textFile("file:\\\\aloha\\logfolder\\sample.txt") 
val inp = sc.textFile('file:\\\\aloha\\logfolder\\sample.txt') 

但似乎沒有工作。

當我將同一個文件複製到我的C盤,它的工作。

val inp = sc.textFile("C:\\Desktop\\logfolder\\sample.txt') 

有什麼想法我錯過了什麼?

回答

2

據我所知SparkContext.textfile()無法在Windows上使用UNC路徑加載文件。 see similar issue

/** 
    * Read a text file from HDFS, a local file system (available on all nodes), or any 
    * Hadoop-supported file system URI, and return it as an RDD of Strings. 
    */ 
    def textFile(
     path: String, 
     minPartitions: Int = defaultMinPartitions): RDD[String] = withScope { 
    assertNotStopped() 
    hadoopFile(path, classOf[TextInputFormat], classOf[LongWritable], classOf[Text], 
     minPartitions).map(pair => pair._2.toString).setName(path) 
    } 
+0

謝謝拉姆。你知道任何其他解決方法來讀取火花中的這些文件嗎? – user7264473

+0

使用'robocopy'手動或本地複製它們到hdfs,這是我所知道的唯一的東西。 –