在集群中使用文件加载graph
从hdfs上加载文件并创建graph
scala> var graphs = GraphLoader.edgeListFile(sc,"/tmp/dataTest/graphTest.txt")
graphs: org.apache.spark.graphx.Graph[Int,Int] = org.apache.spark.graphx.impl.GraphImpl@ab5670d
scala> val graphs = GraphLoader.edgeListFile(sc, "/tmp/dataTest/graphTest.txt",numEdgePartitions=)
graphs: org.apache.spark.graphx.Graph[Int,Int] = org.apache.spark.graphx.impl.GraphImpl@409ea4d1
scala> var verttmp = graphs.mapVertices((id,attr) => attr*)
verttmp: org.apache.spark.graphx.Graph[Int,Int] = org.apache.spark.graphx.impl.GraphImpl@25d7eb44
scala> verttmp.vertices.take()
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_37_0]
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_37_1]
res4: Array[(org.apache.spark.graphx.VertexId, Int)] = Array((,), (,), (,), (,), (,), (,), (,), (,), (,), (,))
scala> var verttmp = graphs.mapVertices((_,attr) => attr*)
verttmp: org.apache.spark.graphx.Graph[Int,Int] = org.apache.spark.graphx.impl.GraphImpl@76828ce4
scala> var edgetmp=graphs.mapEdges(e => e.attr*)
edgetmp: org.apache.spark.graphx.Graph[Int,Int] = org.apache.spark.graphx.impl.GraphImpl@42ce3be7
scala> edgetmp.edges.take()
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_26_0]
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_26_1]
res6: Array[org.apache.spark.graphx.Edge[Int]] = Array(Edge(,,), Edge(,,), Edge(,,), Edge(,,), Edge(,,), Edge(,,), Edge(,,), Edge(,,), Edge(,,), Edge(,,))
scala> var triptmp = graphs.mapTriplets(t => t.srcAttr* + t.dstAttr*)
triptmp: org.apache.spark.graphx.Graph[Int,Int] = org.apache.spark.graphx.impl.GraphImpl@318ec664
scala> triptmp.triplets.take()
[Stage :> ( + ) / ]// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_26_0]
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_26_1]
res7: Array[org.apache.spark.graphx.EdgeTriplet[Int,Int]] = Array(((,),(,),), ((,),(,),), ((,),(,),), ((,),(,),), ((,),(,),), ((,),(,),), ((,),(,),), ((,),(,),), ((,),(,),), ((,),(,),))
class Graph[VD, ED] {
def reverse: Graph[VD, ED]
def subgraph(epred: EdgeTriplet[VD,ED] => Boolean,
vpred: (VertexId, VD) => Boolean): Graph[VD, ED]
def mask[VD2, ED2](other: Graph[VD2, ED2]): Graph[VD, ED]
def groupEdges(merge: (ED, ED) => ED): Graph[VD,ED]
}
def subgraph(epred: EdgeTriplet[VD,ED] => Boolean,
vpred: (VertexId, VD) => Boolean): Graph[VD, ED]
//改函数返回的graph是满足一个boolean条件的graph
//vd就是verticesRdd,包含vertexId和attr vpred:(vertexId,(vertexId,attr))
scala> var subg = graphs.subgraph(epred = e =>e.srcId>e.dstId)
subg: org.apache.spark.graphx.Graph[Int,Int] = org.apache.spark.graphx.impl.GraphImpl@51483f93
scala> subg.edges.take()
res12: Array[org.apache.spark.graphx.Edge[Int]] = Array(
Edge(,,),
Edge(,,),
Edge(,,),
Edge(,,),
Edge(,,),
Edge(,,),
Edge(,,),
Edge(,,),
Edge(,,),
Edge(,,))
scala> subg.vertices.count
res11: Long =
scala> subg.edges.count
res13: Long =
scala> graphs.vertices.count
res9: Long =
scala> graphs.edges.count
res10: Long =
scala> graphs.inDegrees
res15: Array[(org.apache.spark.graphx.VertexId, Int)] = Array((,),
(,), (,), (,), (,), (,),
(,))
scala> graphs.outDegrees.collect
[Stage :>( + ) / ]// :: WARN executor.Executor:
res18: Array[(org.apache.spark.graphx.VertexId, Int)] = Array((,), (,),
(,), (,), (,), (,), (,),
(,), (,), (,), (,), (,))
scala> def max(a:(VertexId,Int),b:(VertexId,Int))={if(a._2>b._2) a else b }
max: (a: (org.apache.spark.graphx.VertexId, Int), b: (org.apache.spark.graphx.VertexId, Int))
(org.apache.spark.graphx.VertexId, Int)
scala> graphs.inDegrees.reduce(max)
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_14_0]
res35: (org.apache.spark.graphx.VertexId, Int) = (,) scala> graphs.outDegrees.reduce(max)
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_14_0]
res36: (org.apache.spark.graphx.VertexId, Int) = (,) scala> graphs.degrees.reduce(max)
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_14_0]
res38: (org.apache.spark.graphx.VertexId, Int) = (,)
scala> var rawG=graphs.mapVertices((id,attr) => )
rawG: org.apache.spark.graphx.Graph[Int,String] = org.apache.spark.graphx.impl.GraphImpl@43d06473
scala> rawG.vertices.collect
res47: Array[(org.apache.spark.graphx.VertexId, Int)] = Array((,), (,), (,), (,))
scala> var ind=rawG.inDegrees;
ind: org.apache.spark.graphx.VertexRDD[Int] = VertexRDDImpl[] at RDD at VertexRDD.scala:
scala> ind.collect
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_60_0]
res49: Array[(org.apache.spark.graphx.VertexId, Int)] = Array((,), (,), (,))
scala> var temp=rawG.joinVertices[Int](ind)((_,_,optdeg) => optdeg)
temp: org.apache.spark.graphx.Graph[Int,String] = org.apache.spark.graphx.impl.GraphImpl@af0e7ce
scala> temp.vertices.take();
// :: WARN executor.Executor: block locks were not released by TID = :
[rdd_60_0, rdd_77_0]
res51: Array[(org.apache.spark.graphx.VertexId, Int)] = Array((,), (,), (,), (,))
在集群中使用文件加载graph的更多相关文章
- 虹软人脸识别在 linux中so文件加载不到的问题
其实是可以加载到的,不过是so文件放的位置不一对,最简单的方式是放在 /usr/lib64 目录下,也可自己设置. so文件加载不到会报这个错误: .lang.UnsatisfiedLinkEr ...
- 读书笔记(一)—— 浅析浏览器渲染过程和html中的文件加载
在构建页面时,我们会在html中载入一个或多个css和js文件.或许大家都已经习惯了"最佳实践"中,css文件应该放在<head>标签中引入,而js文件则是放在< ...
- ssm中静态文件加载路径
项目在本地软件和在服务器上的项目路径如果写死,有可能会出现项目在本机上可以访问,架设在服务器上后就不能访问 这儿介绍在ssm框架中使用 @WebServlet(urlPatterns = {},loa ...
- js中xml文件加载
- 前端设计中关于外部js文件加载的速度优化
在一般情况下,许多人都是将<script>写在了<head>标签中,而许多浏览器都是使用单一的线程来加载js文件的,从上往下,从左往右. 若是加载过程出错,那么网页就会阻塞,就 ...
- redis/分布式文件存储系统/数据库 存储session,解决负载均衡集群中session不一致问题
先来说下session和cookie的异同 session和cookie不仅仅是一个存放在服务器端,一个存放在客户端那么笼统 session虽然存放在服务器端,但是也需要和客户端相互匹配,试想一个浏览 ...
- 在seajs中使用require加载静态文件的问题
注意,在seajs中使用require加载静态文件时,必须使用常量,不能用变量.如果一定要用变量,请使用require.async var html = require("view/sys/ ...
- html文件在head标签中引入js地址和直接写js代码,所用时间是不同的,因为引入js地址,文件加载的时候需要通过通讯协议去解析地址,读取外部文件
html文件在head标签中引入js地址和直接写js代码,所用时间是不同的,因为引入js地址,文件加载的时候需要通过通讯协议去解析地址,读取外部文件
- Java中的资源文件加载方式
文件加载方式有两种: 使用文件系统自带的路径机制,一个应用程序只能有一个当前目录,但可以有Path变量来访问多个目录 使用ClassPath路径机制,类路径跟Path全局变量一样也是有多个值 在Jav ...
随机推荐
- 动态读取cron表达式
项目中在使用任务调度时往往会用到cron表达式,比如每五分钟执行一次,每天12点执行一次,每周四凌晨1点执行一次等.但是如果将cron表达式写死,往往不利于测试.解决方案:我们可以将cron表达式写入 ...
- FZU-2267 The Bigger the Better(字符串,模拟)
Problem 2267 The Bigger the Better Accept: 132 Submit: 935Time Limit: 1500 mSec Memory Limit ...
- 树链剖分【p3038】[USACO11DEC]牧草种植Grass Planting
表示看不太清. 概括题意 树上维护区间修改与区间和查询. 很明显树剖裸题,切掉,细节处错误T了好久 TAT 代码 #include<cstdio> #include<cstdlib& ...
- Remove Duplicate Letters -- LeetCode
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- luogu P3819 松江1843路
题目描述 涞坊路是一条长L米的道路,道路上的坐标范围从0到L,路上有N座房子,第i座房子建在坐标为x[i]的地方,其中住了r[i]人. 松江1843路公交车要在这条路上建一个公交站,市政府希望让最多的 ...
- SQL表操作
//创建一个名为TEST1的表空间 CREATE SMALLFILE TABLESPACE "TEST1" DATAFILE 'G:\ORACLE_11G\ORADATA\ORCL ...
- vue.js 微信浏览器不支持lambda表达式
最近尝试在用vue重构一个微信网页,然后发现在本地测试是可以的,在微信测试工具里也是正常的,然后在手机里有人正常有人不正常,后来发现规律,微信比较新的是不支持的,微信比较旧的是不支持的.然后网上谷歌了 ...
- Apache压力(并发)测试工具ab的使用教程收集
说明:用ab的好处,在处理多并发的情况下不用自己写线程模拟.其实这个世界除了LoadRunner之外还是有很多方案可以选择的. 官网: http://httpd.apache.org/(Apache服 ...
- Python学习笔记——对象
Python 的对象定义方式如下: class Person: def __init__(self, name): self.name = name ...
- JSONP 安全攻防技术(JSON劫持、 XSS漏洞)
关于 JSONP JSONP 全称是 JSON with Padding ,是基于 JSON 格式的为解决跨域请求资源而产生的解决方案.他实现的基本原理是利用了 HTML 里 <script&g ...