package org.apache.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.
* @param path path to the text file on a supported file system
* @param minPartitions suggested minimum number of partitions for the resulting RDD
* @return RDD of lines of the text file
从HDFS、本地文件系统(在所有节点上可用)或任何节点读取文本文件
支持hadoop的文件系统URI,并将其作为字符串的RDD返回。
* @param路径到受支持的文件系统上的文本文件的路径
* @param minPartitions建议结果RDD的最小分区数
* @返回文本文件行的RDD
*/
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包下的flatmap方法怎么跳到了hadoop的包下。而且这几个类,使我们在mapreduce代码中用到的类。
Spark是没有读取HDFS文件的方法
的,textFile引用的是MR的方法,
MR在读文件的时候,首先把文件划
分成一个个
split切片,严格地说,partition与
split-对应, 默认情况下 :
block數= split数
split数= partition数
所以:
block數= partition数