二、Spark源码-- RDD生成及转换过程

本文深入探讨Spark的RDD生成,包括从文件读取的HadoopRDD和从集合创建的ParallelCollectionRDD。在转换过程中,通过FlatMap和Map操作将数据转化为MapPartitionsRDD,接着使用reduceByKey进行数据聚合,此操作实际上调用了combineByKeyWithClassTag方法,生成Shuffle类型的RDD。整个流程展示了RDD在转换过程中的内部变化。
摘要由CSDN通过智能技术生成

本篇从源码角度介绍下RDD的生成和转换过程

RDD生成过程

RDD生成有几种方式,最常用的是sparkContext.textFile方法

 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)
 }

 def hadoopFile[K, V](
     path: String,
     inputFormatClass: Class[_ <: InputFormat[K, V]],
     keyClass: Class[K],
     valueClass: Class[V],
     minPartitions: Int = defaultMinPartitions): RDD[(K, V)] = withScope {
   
   assertNotStopped()

   // This is a hack to enforce loading hdfs-site.xml.
   // See SPARK-11227 for details.
   FileSystem.getLocal(hadoopConfiguration)

   // A Hadoop configuration can be about 10 KB, which is pretty big, so broadcast it.
   val confBroadcast = broadcast(new SerializableConfiguration(hadoopConfiguration))
   val setInputPathsFunc = (jobConf: JobConf) => FileInputFormat.setInputP
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值