1.textFile:
其定义为:def textFile(path: String, minPartitions: Int = defaultMinPartitions): RDD[String];从HDFS,本地或者任何Hadoop支持的文件系统URI读取文件,返回String RDD。
2.wholeTextFiles:
其定义为:def wholeTextFiles(path: String, minPartitions: Int = defaultMinPartitions): RDD[(String, String)];例如,有下列文件:
hdfs://a-hdfs-path/part-00000
hdfs://a-hdfs-path/part-00001
…
hdfs://a-hdfs-path/part-nnnnn
读取:
val rdd = sparkContext.wholeTextFile(“hdfs://a-hdfs-path”)
之后RDD所包含的内容:
(a-hdfs-path/part-00000, its content)
(a-hdfs-path/part-00001, its content)
…
(a-hdfs-path/part-nnnnn, its content)
3.binaryFiles:
用于读取二进制文件,跟wholeTextFiles的用法相同。
Spark读取文件
最新推荐文章于 2024-04-16 00:00:00 发布