Spark读取文件
2015-07-04 12:05
260 查看
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的用法相同。
其定义为: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随谈——开发指南(译)
- Spark,一种快速数据分析替代方案
- Spark初探
- Spark Streaming初探
- 搭建hadoop/spark集群环境
- 整合Kafka到Spark Streaming——代码示例和挑战
- Spark 性能相关参数配置详解-任务调度篇
- 基于spark1.3.1的spark-sql实战-01
- 基于spark1.3.1的spark-sql实战-02
- 使用openfire,spark,fastpath webchat搭建在线咨询服务详细图文解说
- Spark源码分析(1) 从WordCount示例看Spark延迟计算原理
- spark自带示例一
- 在Tachyon上面运行Spark
- Ubuntu12.04(64bit)上部署编译运行Openfire+Spark环境
- ubuntu装spark openfire
- 开始spark之旅
- spark的几点备忘
- Spark学习资料
- spark overview
- 基于spark1.3.1的spark-sql实战-02