Spark GraphX 聚合操作

news/2024/10/23 12:29:30/
package Spark_GraphXimport org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.graphx._
import org.apache.spark.graphx.util.GraphGenerators/*** 计算每一个用户的追随者数量和追随者的平均年龄*/
object Graphx_聚合操作 {def main(args: Array[String]): Unit = {val conf=new SparkConf().setAppName("聚合操作").setMaster("local[2]")val sc=new SparkContext(conf)//随机生成具有100个顶点的图,图的结构也随机val graph:Graph[Double,Int]=GraphGenerators.logNormalGraph(sc,numVertices =100).mapVertices((id,_)=>id.toDouble)graph.vertices.foreach(println)graph.edges.foreach(println)val olderFollowers:VertexRDD[(Int,Double)]=graph.aggregateMessages[(Int,Double)](triplet=>{if(triplet.srcAttr>triplet.dstAttr){    //如果源顶点的属性大于目的顶点的属性triplet.sendToDst(1,triplet.srcAttr)   //源-->目的 发送个数1 和源顶点的属性
        }},(a,b)=>(a._1+b._1,a._2+b._2)     //累加统计结果
    )olderFollowers.values.foreach(println)val avgAgeOfOlderFollowers:VertexRDD[Double]=olderFollowers.mapValues((id,value)=>value match {case (count,totalAge)=>totalAge/count})println("*********************")avgAgeOfOlderFollowers.foreach(println)}}
(34,34.0)
(19,19.0)
(52,52.0)
(39,39.0)
(96,96.0)
(81,81.0)
(4,4.0)
(71,71.0)
(16,16.0)
(55,55.0)
(82,82.0)
(29,29.0)
(66,66.0)
(79,79.0)
(28,28.0)
(65,65.0)
(54,54.0)
(11,11.0)
(40,40.0)
(23,23.0)
(6,6.0)
(67,67.0)
(8,8.0)
(69,69.0)
(86,86.0)
(3,3.0)
(58,58.0)
(7,7.0)
(44,44.0)
(85,85.0)
(88,88.0)
(91,91.0)
(60,60.0)
(31,31.0)
(26,26.0)
(87,87.0)
(68,68.0)
(5,5.0)
(2,2.0)
Edge(50,1,1)
Edge(0,58,1)
Edge(50,25,1)
Edge(1,4,1)
Edge(51,0,1)
Edge(1,5,1)
Edge(51,1,1)
Edge(1,6,1)
Edge(51,2,1)
Edge(1,10,1)
Edge(1,27,1)
Edge(1,27,1)
Edge(1,29,1)
Edge(1,33,1)
Edge(1,34,1)
Edge(1,37,1)
Edge(1,39,1)
Edge(1,42,1)
Edge(51,8,1)
Edge(1,45,1)
Edge(51,9,1)
Edge(1,46,1)
Edge(51,10,1)
Edge(1,47,1)
Edge(51,13,1)
Edge(1,48,1)
Edge(51,13,1)
Edge(1,48,1)
Edge(51,14,1)
Edge(5,5,1)
Edge(5,10,1)
Edge(5,12,1)
Edge(5,13,1)
Edge(5,13,1)
Edge(5,15,1)
Edge(5,17,1)
Edge(5,17,1)
Edge(5,17,1)
Edge(5,17,1)
Edge(5,20,1)
Edge(5,20,1)
Edge(5,22,1)
...........................     省略
...........................     省略
(38,2568.0)
(51,2920.0)
(30,2155.0)
(52,3016.0)
(2,196.0)
(29,2010.0)
(50,2820.0)
(8,736.0)
(40,2247.0)
(17,1567.0)
(8,675.0)
(16,1329.0)
(30,2422.0)
(40,2713.0)
(43,2699.0)
(20,1415.0)
(10,873.0)
(15,1383.0)
(20,1663.0)
(39,2124.0)
(1,99.0)
(39,2440.0)
(37,2487.0)
(54,3089.0)
(13,1080.0)
(14,1172.0)
(21,1615.0)
(30,2079.0)
(37,2555.0)
(42,2832.0)
(12,1036.0)
(13,1118.0)
(26,1899.0)
(11,1067.0)
(61,3382.0)
(19,1675.0)
(6,555.0)
(7,667.0)
(12,994.0)
(14,1204.0)
(13,1220.0)
(17,1457.0)
(46,2838.0)
(45,2699.0)
(53,2946.0)
(63,3344.0)
(19,1433.0)
(42,2806.0)
(22,1582.0)
(51,3087.0)
(16,1394.0)
(10,926.0)
(47,2411.0)
(27,2185.0)
(53,3093.0)
(33,2355.0)
(8,734.0)
(10,930.0)
(6,572.0)
(19,1476.0)
(33,1839.0)
(34,2058.0)
(6,573.0)
(10,837.0)
(52,2814.0)
(59,3208.0)
*********************
(13,57.254901960784316)
(19,58.0)
(39,69.3103448275862)
(81,92.0)
(71,84.375)
(55,80.73333333333333)
(29,62.76744186046512)
(79,87.3)
(65,83.15)
(11,54.46153846153846)
(35,67.21621621621621)
(57,83.07692307692308)
(34,67.57894736842105)
(52,71.83333333333333)
(96,98.0)
(4,56.4)
(16,56.175)
(82,92.17647058823529)
(66,83.0625)
(28,67.825)
(54,70.75)
(80,92.2)
(98,99.0)
(30,62.56410256410256)
(14,57.2037037037037)
(50,83.71428571428571)
(36,69.3)
(24,67.42857142857143)
(64,86.0)
(92,97.0)
(74,88.15789473684211)
(90,95.28571428571429)
(72,86.0)
(70,85.70588235294117)
(18,59.977777777777774)
(12,53.07936507936508)
(38,66.80952380952381)
(20,60.529411764705884)
(78,90.88888888888889)
(10,54.36206896551724)
(94,96.85714285714286)
(84,94.85714285714286)
(56,79.47826086956522)
(76,88.25)
(22,55.484848484848484)
(46,75.97222222222223)
(48,70.38095238095238)
(32,63.86363636363637)
(0,47.06349206349206)
(62,88.75)
(42,70.54166666666667)
(40,71.09677419354838)
(6,55.21875)
(8,54.638297872340424)
(86,92.6)
(58,80.92592592592592)
(44,71.36363636363636)
(88,93.0)
(60,77.6842105263158)
(26,60.529411764705884)
(68,83.7)
(2,54.3728813559322)
(51,76.9047619047619)
(37,69.05405405405405)
(75,86.33333333333333)
(45,73.03846153846153)
(1,55.442622950819676)
(89,92.5)
(63,82.83333333333333)
(83,93.84615384615384)
(17,61.69565217391305)
(9,55.58490566037736)
(49,75.42105263157895)
(43,71.9090909090909)
(41,74.18518518518519)
(61,78.62962962962963)
(15,52.0)
(21,58.244897959183675)
(47,71.15384615384616)
(77,88.25)
(53,71.9090909090909)
(25,62.40384615384615)
(95,97.7)
(59,85.57142857142857)
(73,91.58333333333333)
(27,65.77142857142857)
(93,96.14285714285714)
(33,61.8)
(23,58.84)
(67,85.14285714285714)
(69,87.125)
(3,51.297872340425535)
(7,58.35849056603774)
(85,91.75)
(91,95.33333333333333)
(31,55.72727272727273)
(87,95.5)
(5,54.11538461538461)

 

转载于:https://www.cnblogs.com/soyo/p/7890935.html


http://www.ppmy.cn/news/505731.html

相关文章

[二分答案] P2920 Time Management

推导贪心条件 排序 二分 输出 //#pragma GCC optimize(2) #include <cstdio> #include <iostream> #include <cstdlib> #include <cmath> #include <cctype> #include <string> #include <cstring> #include <algorithm> #…

Spring Boot 中自定义数据校验注解

Spring Boot 中自定义数据校验注解 在 Spring Boot 中&#xff0c;我们可以使用 JSR-303 数据校验规范来校验表单数据的合法性。JSR-303 提供了一些常用的数据校验注解&#xff0c;例如 NotNull、NotBlank、Size 等。但是&#xff0c;在实际开发中&#xff0c;我们可能需要自定…

【莫比乌斯反演】BZOJ2920-YY的GCD

【题目大意】 给定N, M,求1<x<N, 1<y<M且gcd(x, y)为质数的(x, y)有多少对。 【思路】 太神了这道题……蒟蒻只能放放题解&#xff1a;戳&#xff0c;明早再过来看看还会不会推导过程…… 实用的结论&#xff1a; 嗯…… /***************************************…

2920集五福_支付宝集五福攻略 ▏顺便学点营销活动传播套路

到今天为止&#xff0c;你一共收齐了几张福卡了呢&#xff1f; 本月5号&#xff0c;支付宝在微信公众号里发了《新年俗 集五福》的推文&#xff0c;“2月6日0点&#xff0c;支付宝里见&#xff0c;有你们就有福”。 同时&#xff0c;一名叫“青春、已不在”的网友立马在下方评论…

2920X

演讲不是讲自己的话&#xff0c;而是将听众的话&#xff0c;还记得那些演讲失败者&#xff0c;离开舞台的最后一段话&#xff0c;他们的感言就是我们失败的原因历史总是惊人的相似举例子是为了增加信服性历史是如此的悠久&#xff0c;还有什么故事不能符合我任何贪婪的意愿我的…

java多线程简明笔记(5)线程礼让 yield

关键字&#xff1a;yield 官方文档就不说了&#xff0c;简单理解&#xff0c;礼让 线程礼让 yield正在执行的线程暂停&#xff0c;不阻塞 示例代码&#xff1a; public class ThreadTest7 implements Runnable{public static void main(String[] args) {ThreadTest7 tnew Th…

雅思词汇真经单词共3672个

雅思词汇真经 / Vocabulary for IELTS / 学为贵 赢未来 / 英语真经派学习法 一本书精通雅思词汇 / 刘洪波 编著 / 涵盖&#xff1a;雅思必备核心词汇刘洪波老师原创雅思考点词库 逻辑词群记忆法&#xff0c;一群一群记单词&#xff0c;快速备考无负责 时尚插图&#xff0c;趣味…

大一上:英语复习:Word in use(新视野大学英语读写教程1:第一、三、四、六单元翻译+注释)【四大人工智能翻译辅助系统助力翻译更准确】

文档下载地址&#xff1a;https://pan.baidu.com/s/1qYDT6rU Word in use Unit 1 A 1.Given the chance to show his ability, he regained confidence and began to succeed in school. [自然智力神经系统翻译&#xff08;我翻译的&#xff09;]自从获得了…