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方法一直報找不到文件,node

在另外兩個work中複製這個文件以後,就能夠讀取文件了)ide

sc.textFile("file:///root/wc/sparkInput")在idea中讀取本地文件是因爲本地環境中有hadoop的環境變量.在集羣中若是須要加載本地的文件還不如傳到hdfs上,而後從hdfs中讀取數據.(spark用的是1.6.1)由於
相關文章
相關標籤/搜索