码迷,mamicode.com
首页 > 其他好文 > 详细

Spark-GraphX入门

时间:2019-11-05 01:14:53      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:oca   ack   set   打印   cal   war   iso   doc   ast   

//1.准备环境
val conf: SparkConf = new SparkConf().setAppName("_01SparkGraphx").setMaster("local[*]")
val sc: SparkContext = new SparkContext(conf)
sc.setLogLevel("WARN")

//2.准备数据
val vertexData: RDD[(VertexId, (String, String))] = sc.parallelize(Array(
(3L, ("rxin", "stu")),
(5L, ("franklin", "prof")),
(7L, ("c", "pstdoc")),
(2L, ("d", "prof"))
))
//3.准备边的数据
val edgeData: RDD[Edge[String]] = sc.parallelize(Array(
Edge(3L, 7L, "coola"),
Edge(5L, 3L, "Advisor"),
Edge(5L, 7L, "PI"),
Edge(2L, 5L, "Collage")
))
//4.构建图
val graph: Graph[(String, String), String] = Graph(vertexData,edgeData)
//5.
println("graph edges:")
graph.edges.foreach(println(_))
//打印顶点的个数
val vertices: VertexId = graph.numVertices
println("vertrex num is",vertices)
//打印边的个数
val edges: VertexId = graph.numEdges
println("edges",edges)

Spark-GraphX入门

标签:oca   ack   set   打印   cal   war   iso   doc   ast   

原文地址:https://www.cnblogs.com/note-djl/p/11795910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!