graph小案例
scala> import org.apache.spark._
import org.apache.spark._
scala> import org.apache.spark.rdd.RDD
import org.apache.spark.rdd.RDD
scala> import org.apache.spark.graphx._
import org.apache.spark.graphx._
scala> import org.apache.spark.graphx.util._
import org.apache.spark.graphx.util._
scala> var graphs =
GraphGenerators.logNormalGraph(sc, numVertices = 5).mapVertices( (id, _) => id.toDouble )
graphs: org.apache.spark.graphx.Graph[Double,Int] = org.apache.spark.graphx.impl.GraphImpl@1461f52d
VertexId, Double)] = Array((4,4.0), (0,0.0), (1,1.0), (3,3.0), (2,2.0))
srcid attr srcid:选手编号 attr:年龄
0 0
1 1
2 2
3 3
4 4
Array(Edge(0,1,1), Edge(0,1,1), Edge(0,3,1), Edge(0,4,1), Edge(1,2,1), Edge(1,4,1), Edge(2,0,1), Edge(2,0,1), Edge(2,3,1), Edge(2,4,1), Edge(3,3,1), Edge(4,0,1), Edge(4,3,1))
srcid dstid attr srcid:追随者 dstid:被追随者 attr:年龄
0 1 1
0 1 1
0 3 1
0 4 1
1 2 1
1 4 1
2 0 1
2 0 1
2 3 1
2 4 1
1 3 1
4 0 1
4 3 1
scala> val olderFollowers: VertexRDD[(Int, Double)] = graphs.aggregateMessages[(Int, Double)](
| triplet => { // Map Function
| if (triplet.srcAttr > triplet.dstAttr) {
| // Send message to destination vertex containing counter and age
| triplet.sendToDst(1, triplet.srcAttr)
| }
| },
| // Add counter and age
| (a, b) => (a._1 + b._1, a._2 + b._2) // Reduce Function
| )
res3: Array[(org.apache.spark.graphx.VertexId, (Int, Double))] = Array((0,(3,8.0)), (3,(1,4.0)))
scala> val avgAgeOfOlderFollowers: VertexRDD[Double] =
| olderFollowers.mapValues( (id, value) =>
| value match { case (count, totalAge) => totalAge / count } )
avgAgeOfOlderFollowers: org.apache.spark.graphx.VertexRDD[Double] = VertexRDDImpl[48] at RDD at VertexRDD.scala:57
graph小案例的更多相关文章
- 机械表小案例之transform的应用
这个小案例主要是对transform的应用. 时钟的3个表针分别是3个png图片,通过setInterval来让图片转动.时,分,秒的转动角度分别是30,6,6度. 首先,通过new Date函数获取 ...
- shell讲解-小案例
shell讲解-小案例 一.文件拷贝输出检查 下面测试文件拷贝是否正常,如果cp命令并没有拷贝文件myfile到myfile.bak,则打印错误信息.注意错误信息中basename $0打印脚本名.如 ...
- [jQuery学习系列六]6-jQuery实际操作小案例
前言最后在这里po上jQuery的几个小案例. Jquery例子1_占位符使用需求: 点击第一个按钮后 自动去check 后面是否有按钮没有选中, 如有则提示错误消息. <html> &l ...
- 02SpringMvc_springmvc快速入门小案例(XML版本)
这篇文章中,我们要写一个入门案例,去整体了解整个SpringMVC. 先给出整个项目的结构图:
- React.js入门小案例
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...
- SqlDependency缓存数据库表小案例
SqlDependency的简介: SqlDependency是outputcache网页缓存的一个参数,它的作用是指定缓存失效的数据库依赖项,可以具体到数据库和表. SqlDependency能解决 ...
- JavaScript apply函数小案例
//回调函数1 function callback(a,b,c) { alert(a+b+c); } //回调函数2 function callback2(a,b) { alert(a+b); } / ...
- Session小案例------完成用户登录
Session小案例------完成用户登录 在项目开发中,用户登陆功能再平常只是啦,当用户完毕username和password校验后.进入主界面,须要在主界面中显示用户的信息,此时用ses ...
- ch1-vuejs基础入门(hw v-bind v-if v-for v-on v-model 应用组件简介 小案例)
1 hello world 引入vue.min.js 代码: ----2.0+版本 <div id="test"> {{str}} </div> <s ...
随机推荐
- 51 nod 1419 最小公倍数挑战【数论/互质+思维】
1419 最小公倍数挑战 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 几天以前,我学习了最小公倍数.玩得挺久了 ...
- oracle数据迁移之Exp和Expdp导出数据的性能对比与优化
https://wangbinbin0326.github.io/2017/03/31/oracle%E6%95%B0%E6%8D%AE%E8%BF%81%E7%A7%BB%E4%B9%8BExp%E ...
- Hibernate使用Criteria去重distinct+分页
写在前面: 最近在项目中使用了Criteria的分页查询,当查询的数据没有重复的记录还好,但是当数据有关联并出现重复记录的时候,就要去重,那么就会出现查询的记录数与实际的不一致的问题.这里也记录一下解 ...
- Stage3D 中的PerspectiveMatrix3D
PerspectiveMatrix3D继承自Matrix3D.表示投影矩阵的功能类. 公式:用4X4矩阵向z=d的平面投影 public function perspectiveFieldOfView ...
- 五. 面向对象高级特性1. Java内部类及其实例化
在 Java 中,允许在一个类(或方法.语句块)的内部定义另一个类,称为内部类(Inner Class),有时也称为嵌套类(Nested Class). 内部类和外层封装它的类之间存在逻辑上的所属关系 ...
- 【状态压缩DP】【BZOJ1087】【SCOI2005】互不侵犯king
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3135 Solved: 1825[Submit][ ...
- 警告Conversion specifies type'int' but the argument has type'size_t'
代码: #import<Foundation/Foundation.h> int main(int argc,const char * argv[]){ const char *words ...
- MySQL集群---②Windows平台搭建MySQL CLUSTER集群
原文:http://blog.csdn.net/mazhaojuan/article/details/42211857 本文将通过两台电脑来简单介绍一下Windows平台如何搭建MySQL集群. My ...
- Eclipse常用小知识汇总
原文:http://blog.csdn.net/jinzhencs/article/details/50462370 1.修改注释 自动出来的author
- Has anybody found a way to load HTTPS pages with an invalid server certificate using UIWebView?
If a user attempts to load a https web page in Mobile Safari and the server's certificate validation ...