GraphX 的属性图
Posted 见贤思小齐,知足常乐呵
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GraphX 的属性图相关的知识,希望对你有一定的参考价值。
package main.scala import org.apache.spark.graphx.{Edge, Graph, VertexId} import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} object graph_test { // define hadoop_home directory System.setProperty("hadoop.home.dir","E:/zhuangji/winutil/") def main(args:Array[String]):Unit={ val conf=new SparkConf().setMaster("local[2]").setAppName("graph_test") val sc=new SparkContext(conf) // VertexRDD & EdgeRDD to build graph val users:RDD[(VertexId,(String,String))]= sc.parallelize(Array((3L,("rxin","student")),(7L,("jgonzal","postdoc")), (5L,("franklin","prof")),(2L,("istoica","prof")))) val relationships:RDD[Edge[String]]= sc.parallelize(Array(Edge(3L,7L,"collab"),Edge(5L,3L,"advisor"), Edge(2L,5L,"colleague"),Edge(5L,7L,"pi"))) val defaultUser=("John Doe","Missing") val graph=Graph(users,relationships,defaultUser) // graph.vertices & graph.edges to query graph println(graph.vertices.filter{case (id,(name,pos))=>pos=="prof"}.count) println(graph.edges.filter{case Edge(s,d,r)=>s<d}.count) // 两者 println(graph.edges.filter(e=>e.srcId<e.dstId).count) // 等价 // 三元组视图 graph.triplets could also query a graph val facts:RDD[String]= graph.triplets.map(triplet=> triplet.srcAttr._1 + " is the " + triplet.attr + " of " + triplet.dstAttr._1) facts.collect.foreach(println(_)) } }
以上是关于GraphX 的属性图的主要内容,如果未能解决你的问题,请参考以下文章
大数据技术之_19_Spark学习_05_Spark GraphX 应用解析 + Spark GraphX 概述解析 + 计算模式 + Pregel API + 图算法参考代码 + PageRank(