spark讀取本地文件


 /**
   * 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)
因為


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM