1. outerJoinVertices函数

首先给出源代码

 override def outerJoinVertices[U: ClassTag, VD2: ClassTag]
(other: RDD[(VertexId, U)]) //带插入的顶点信息
(updateF: (VertexId, VD, Option[U]) => VD2) //更新函数
(implicit eq: VD =:= VD2 = null): Graph[VD2, ED] = {
// The implicit parameter eq will be populated by the compiler if VD and VD2 are equal, and left
// null if not
    // 其中,VD2表示最终生成的新图的VD类型;VD表示原图的VD类型
if (eq != null) { //如果新旧两个图的VD类型不一致
vertices.cache()
// updateF preserves type, so we can use incremental replication
val newVerts = vertices.leftJoin(other)(updateF).cache() //对图的顶点做左连接
val changedVerts = vertices.asInstanceOf[VertexRDD[VD2]].diff(newVerts) //比较新生成的定点序列与原始定点序列直接修改格式后的序列之间的差异
val newReplicatedVertexView = replicatedVertexView.asInstanceOf[ReplicatedVertexView[VD2, ED]]
.updateVertices(changedVerts) //根据changedVerts构造新的replicatedVertexView
     new GraphImpl(newVerts, newReplicatedVertexView) 
  } else {
// updateF does not preserve type, so we must re-replicate all vertices
val newVerts = vertices.leftJoin(other)(updateF)
    GraphImpl(newVerts, replicatedVertexView.edges)
   }
}

其中, replicatedVertexView的官方解释是:“Manages shipping vertex attributes to the edge partitions of an EdgeRDD. Vertex attributes may be partially shipped to construct a triplet view with vertex attributes on only one side, and they may be updated. ”    个人理解是在边对象的上面增加了顶点属性。

针对官方的例子:

1 val graph = followerGraph.outerJoinVertices(users) {
2 case (uid, deg, Some(attrList)) => attrList
3 case (uid, deg, None) => Array.empty[String]
4 }

首先介绍代码目的: followerGraph是通过调用GraphLoader.edgeListFile()函数,从边文件中读入的。由于边文件中只存储了相应的顶点编号,没有定点对应的属性。因此需要使用user(VertexId, attr)来将定点信息补全。

其中,deg为followerGraph的顶点属性,case的第三个参数attrList表示user的顶点属性。箭头(=>)后的attrList表示修改后followerGraph的顶点属性。

通过源代码可以看出,在执行outerJoinVertices时,首先执行的是顶点序列(VertexRDD)的LeftJoin,也就是将顶点编号一致的顶点的属性替换到followerGraph中。

Spark GraphX的函数源码分析及应用实例的更多相关文章

  1. Vue中之nextTick函数源码分析

    Vue中之nextTick函数源码分析 1. 什么是Vue.nextTick()?官方文档解释如下:在下次DOM更新循环结束之后执行的延迟回调.在修改数据之后立即使用这个方法,获取更新后的DOM. 2 ...

  2. PHP 源码 — intval 函数源码分析

    PHP 源码 - intval 函数源码分析 文章来源: https://github.com/suhanyujie/learn-computer/ 作者:suhanyujie 基于PHP 7.3.3 ...

  3. PHP 源码 —— is_array 函数源码分析

    is_array 函数源码分析 本文首发于 https://github.com/suhanyujie/learn-computer/blob/master/src/function/array/is ...

  4. 序列化器中钩子函数源码分析、many关键字源码分析

    局部钩子和全局钩子源码分析(2星) # 入口是 ser.is_valid(),是BaseSerializer的方法 # 最核心的代码 self._validated_data = self.run_v ...

  5. spark的存储系统--BlockManager源码分析

    spark的存储系统--BlockManager源码分析 根据之前的一系列分析,我们对spark作业从创建到调度分发,到执行,最后结果回传driver的过程有了一个大概的了解.但是在分析源码的过程中也 ...

  6. Vue源码分析(二) : Vue实例挂载

    Vue源码分析(二) : Vue实例挂载 author: @TiffanysBear 实例挂载主要是 $mount 方法的实现,在 src/platforms/web/entry-runtime-wi ...

  7. JVM源码分析-类加载场景实例分析

    A类调用B类的静态方法,除了加载B类,但是B类的一个未被调用的方法间接使用到的C类却也被加载了,这个有意思的场景来自一个提问:方法中使用的类型为何在未调用时尝试加载?. 场景如下: public cl ...

  8. Spark MLlib - Decision Tree源码分析

    http://spark.apache.org/docs/latest/mllib-decision-tree.html 以决策树作为开始,因为简单,而且也比较容易用到,当前的boosting或ran ...

  9. 【Spark篇】---Spark中资源和任务调度源码分析与资源配置参数应用

    一.前述 Spark中资源调度是一个非常核心的模块,尤其对于我们提交参数来说,需要具体到某些配置,所以提交配置的参数于源码一一对应,掌握此节对于Spark在任务执行过程中的资源分配会更上一层楼.由于源 ...

随机推荐

  1. poj 1087.A Plug for UNIX (最大流)

    网络流,关键在建图 建图思路在代码里 /* 最大流SAP 邻接表 思路:基本源于FF方法,给每个顶点设定层次标号,和允许弧. 优化: 1.当前弧优化(重要). 1.每找到以条增广路回退到断点(常数优化 ...

  2. 【POJ3580】【块状链表】SuperMemo

    Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant i ...

  3. PHP+MySQL中对UTF-8,UTF8(utf8),set names gbk 的理解

    问题一:在我们进行数据库操作时会发现,数据库中表的编码用的是utf-8,但是在进行dos命令是要使用set names gbk (一)Mysql中默认字符集设置有四级:服务器级,数据库级,表级,和字段 ...

  4. centos 安装vnc服务

    1.安装tigervnc-server yum install tigervnc-server 2.启动vnc服务 vncserver:1 [错误提示待解决bad display name " ...

  5. 16_用LVM扩展xfs文件系统(当分区空间不够时)

    1. 查看当前卷组空间(volume group)使用情况 [root@localhost ~]# vgdisplay 从下面的代码中发现剩余空间为0 --- Volume group --- VG ...

  6. .NET Framework(二)

    在上一篇的随笔中,我们在理论层面上大致说明了.NET Framework的工作机制,内容的确比较晦涩难懂,但是还是希望大家有时候可以看看.我个人觉得,编程不是一味的敲代码,当自己遇到瓶颈的时候,可以多 ...

  7. 数组Api .map()的使用

    之前并没有过多的使用过这个Api,在此记录下对其的理解,方便以后多多使用. 首先是对map的说明: var mappedArray = array.map(callback[, thisObject] ...

  8. nodejs版本控制

    本方法基于https://segmentfault.com/a/1190000004855835修改 配置: 使用的nvmw的git 地址https://github.com/hakobera/nvm ...

  9. JS 导出图片,toDataURL

    //输出图片 function exportCanvasAsPNG(id, fileName) { //获取canvas元素 var canvasElement = document.getEleme ...

  10. linux下shapely的安装

    错误 1.“from shapely.geometry import Point, LineString, Polygon”时报错: OSError: Could not find library g ...