/** * 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) }
由spark的源碼源碼的注釋可以知道,spark可以讀取本地數據文件,但是需要在所有的節點都有這個數據文件(親測,在有三個節點的集群中,只在master中有這個數據文件時執行textFile方法一直報找不到文件,
在另外兩個work中復制這個文件之后,就可以讀取文件了)
sc.textFile("file:///root/wc/sparkInput")
在idea中讀取本地文件是由於本地環境中有hadoop的環境變量.在集群中如果需要加載本地的文件還不如傳到hdfs上,然后從hdfs中讀取數據.
(spark用的是1.6.1)
因為
