GraphX学习笔记——Programming Guide
学习的资料是官网的Programming Guide
https://spark.apache.org/docs/latest/graphx-programming-guide.html
首先是GraphX的简介
GraphX是Spark中专门负责图和图并行计算的组件。
GraphX通过引入了图形概念来继承了Spark RDD:一个连接节点和边的有向图
为了支持图计算,GraphX引入了一些算子: subgraph, joinVertices, and aggregateMessages等
和 Pregel API,此外还有一些algorithms 和 builders 来简化图分析任务。
关于构建 节点Vertex 和 边Edge
1.如果需要将节点定义成一个类
package graphx
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.graphx._
import org.apache.spark.rdd.RDD
import org.graphstream.graph.implementations.{AbstractEdge, SingleGraph, SingleNode}
/**
* Created by common on 18-1-22.
*/
// 抽象节点
class VertexProperty()
// User节点
case class UserProperty(val name: String) extends VertexProperty
// Product节点
case class ProductProperty(val name: String, val price: Double) extends VertexProperty
object GraphxLearning {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("GraphX").setMaster("local")
val sc = new SparkContext(conf)
// The graph might then have the type:
var graph: Graph[VertexProperty, String] = null
}
}
和节点一样,边也可以定义成一个class,同时Graph类需要和定义的节点和边的类型相对应
class Graph[VD, ED] { // VD表示节点类型,ED表示边类型
val vertices: VertexRDD[VD]
val edges: EdgeRDD[ED]
}
2.如果节点的类型比较简单,例如只是一个String或者(String,String),就不需要定义成一个类
package graphx
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.graphx._
import org.apache.spark.rdd.RDD
import org.graphstream.graph.implementations.{AbstractEdge, SingleGraph, SingleNode}
/**
* Created by common on 18-1-22.
*/
object GraphxLearning {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("GraphX").setMaster("local")
val sc = new SparkContext(conf)
// Create an RDD for the vertices
val users: RDD[(VertexId, (String, String))] =
sc.parallelize(Array((3L, ("rxin", "student")), (7L, ("jgonzal", "postdoc")),
(5L, ("franklin", "prof")), (2L, ("istoica", "prof"))))
// Create an RDD for edges
val relationships: RDD[Edge[String]] =
sc.parallelize(Array(Edge(3L, 7L, "collab"), Edge(5L, 3L, "advisor"),
Edge(2L, 5L, "colleague"), Edge(5L, 7L, "pi")))
//Define a default user in case there are relationship with missing user
val defaultUser = ("John Doe", "Missing")
// 使用多个RDDs建立一个Graph,Graph的类型分别是节点加上边的类型,有两种节点,一种有ID,一种没有
val srcGraph: Graph[(String, String), String] = Graph(users, relationships, defaultUser)
}
}
图的一些算子
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GraphX学习笔记——Programming Guide的更多相关文章
- 对Spark2.2.0文档的学习3-Spark Programming Guide
Spark Programming Guide Link:http://spark.apache.org/docs/2.2.0/rdd-programming-guide.html 每个Spark A ...
- GraphX学习笔记——可视化
首先自己造了一份简单的社交关系的图 第一份是人物数据,id和姓名,person.txt 1 孙俪 2 邓超 3 佟大为 4 冯绍峰 5 黄晓明 6 angelababy 7 李冰冰 8 范冰冰 第二份 ...
- CUDA Programming Guide 学习笔记
CUDA学习笔记 GPU架构 GPU围绕流式多处理器(SM)的可扩展阵列搭建,每个GPU有多个SM,每个SM支持数百个线程并发执行.目前Nvidia推出了6种GPU架构(按时间顺序,详见下图):Fer ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- Direct12优化
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- Direct12优化 第一章:向量代数 1.向量计算的时候,使用XMV ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十八章:立方体贴图
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十八章:立方体贴图 代码工程地址: https://github.c ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十三章:计算着色器(The Compute Shader)
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十三章:计算着色器(The Compute Shader) 代码工程 ...
- AngularJs学习笔记--Guide教程系列文章索引
在很久很久以前,一位前辈向我推荐AngularJs.但当时我没有好好学习,仅仅是讲文档浏览了一次.后来觉醒了……于是下定决心好好理解这系列的文档,并意译出来(英文水平不足……不能说是翻译,有些实在是看 ...
- Learning ROS for Robotics Programming Second Edition学习笔记(十) indigo Gazebo rviz slam navigation
中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 moveit是书的最后一章,由于对机械臂完全不知,看不懂 ...
- Learning ROS forRobotics Programming Second Edition学习笔记(八)indigo rviz gazebo
中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS forRobotics Pro ...
随机推荐
- react-native-background-job——让你的react-native项目实现后台运行
安排在您的应用处于后台时运行JavaScript的后台任务. 即使应用程序已关闭,任务也会运行,默认情况下,也会在重新启动后继续存在. 这个库依赖于React Native的HeadlessJS ,目 ...
- PAT-Top1002. Business (35)
在一个项目的截止日期之前,如果工期有空闲则可能可以开展其他项目,提高效益.本题考查动态规划.数组dp[i][t]表示在截止时间为t时,前i个项目工作安排能够产生的最大收益,而前i个项目的截止时间都不大 ...
- bzoj 1006
http://www.cnblogs.com/zxfx100/archive/2011/03/23/1993055.html https://wenku.baidu.com/view/07f4be19 ...
- 深入理解this,bind、call
直接看this 直接看call和bind 首先放一道题: var a={ a:'haha', getA: function(){ console.log(this.a); } } var b= { a ...
- ajax01
ajax01 1.ajax简介 涉及AJAX的操作页面不能用文件协议访问 使用ajax发送请求: send参数缺省默认为null onreadyatatechange事件在状态改变时就会触发. .re ...
- pygame-KidsCanCode系列jumpy-part17-mask-collide碰撞检测
这节我们研究下pygame的几种碰撞检测模式: 如上图,左侧是默认的检测模式:基于矩形的检测(这也是性能最好的模式), 右侧是基于圆形的检测(性能略差于矩形检测). 矩形检测法虽然性能好,但是缺点也很 ...
- Netty 中ChannelOption的含义以及使用的场景
Netty 中ChannelOption的含义以及使用的场景 转自:http://www.cnblogs.com/googlemeoften/p/6082785.html 1.ChannelOptio ...
- windows Docker Desktop 搭建mysql,mssql和redis服务
其实网上关于docker上搭建mysql的文章已经很多了,只是今晚自己搭建的时候遇到一些问题,记录一下 1.首先是pull image , docker pull mysql 2.启动服务 docke ...
- ViewPager Fragment 懒加载 可见 总结 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- freenode configuration sasl authentication in weechat
转自:https://www.weechat.org/files/doc/stable/weechat_user.en.html#irc_sasl_authentication SASL authen ...