[英]spark graphx -creating list of graphs objects in scala
I want to make the edges in the graph to be subgraphs. 我想使图中的边成为子图。 Then I want to join these subgraphs based on a criterion and form cliques. 然后,我想根据一个准则合并这些子图并形成集团。 Basically I want to know how to create a list of Graph
objects. 基本上我想知道如何创建Graph
对象的列表。
How can I achieve this using the Graph X API of Apache Spark in Scala? 如何使用Scala中的Apache Spark的Graph X API实现此目的?
import org.apache.spark._
import org.apache.spark.graphx._
import org.apache.spark.rdd.RDD
import scala.collection.mutable.ArrayBuffer
val cliques = ArrayBuffer[Graph[(String, Int),Int]]()
var edges = sc.textFile("edges.g3").map {
line => var fields = line.split("\\s+")
println(line)
val vertexArray = Array(
(fields(0).toLong, (fields(0), 1)),
(fields(1).toLong, (fields(1), 1)))
val edgeArray = Array(
Edge(fields(0).toLong,fields(1).toLong,0)
)
val vertexRDD: RDD[(Long, (String, Int))] = sc.parallelize(vertexArray)
val edgeRDD: RDD[Edge[Int]] = sc.parallelize(edgeArray)
val graph: Graph[(String, Int),Int] = new Graph(vertexRDD, edgeRDD)
cliques += graph
}
This code gives the error that class Graph
is abstract, hence cannot be instantiated. 这段代码给出了Graph
类是抽象类,因此无法实例化的错误。 Is there any way to create a list of graphs? 有什么方法可以创建图列表?
How to instantiate the Graph object is my main question? 如何实例化Graph对象是我的主要问题?
Instead of new Graph(vertexRDD, edgeRDD)
you need to use Graph(vertexRDD, edgeRDD)
. 代替new Graph(vertexRDD, edgeRDD)
您需要使用Graph(vertexRDD, edgeRDD)
。 Check out some of the examples in the documentation . 查看文档中的一些示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.