>我有一个以这种方式创建的顶点和边的列表:
val v1 = new Vertex(1L, "foo")
val v2 = new Vertex(2L, "bar")
val e1 = new Edge(v1, v2, 0.5)`
并希望使用 Graph.fromDataSet 方法(或任何其他与此相关的方法)创建一个 Flink 图。我怎样才能将这些边和顶点转换为 Flink 可读的内容?
谢谢!!
给定顶点val vertices: Seq[Vertex[Long, String]] = ...
和边的列表val edges: Seq[Edge[Long, String]] = ...
您可以使用Graph.fromCollection
方法创建Graph
:
val env = ExecutionEnvironment.getExecutionEnvironment
val vertices = Seq(new Vertex[Long, String](1L, "foo"), new Vertex[Long, String](2L, "bar"))
val edges = Seq(new Edge[Long, String](1L, 2L, "foobar"))
val graph = Graph.fromCollection(vertices, edges, env)
值得注意的是,您必须导入 Scala 版本的 org.apache.flink.graph.scala.Graph
.
或者,您也可以先使用 ExecutionEnvironment
创建edgeDataset: DataSet[Edge[Long, String]]
和vertexDataSet: DataSet[Vertex[Long, String]]
。然后可以创建调用Graph.fromDataSet
方法的Graph
:
val vertexDataset = env.fromCollection(vertices)
val edgeDataset = env.fromCollection(edges)
val graph = Graph.fromDataSet(vertexDataset, edgeDataset, env)