Graphx Visualization

前端 未结 4 1964
误落风尘
误落风尘 2021-01-31 12:48

I am looking for a way to visualize the graph constructed in Spark\'s Graphx. As far as I know Graphx doesn\'t have any visualization methods so I need to export the data from G

4条回答
  •  野的像风
    2021-01-31 12:58

    If you're using grpahFrames, then I've modified the code provided by @Karol Sudol in his answer for GraphFrames:

        def drawGraph[vertices:ClassTag,relations:ClassTag](g:GraphFrame) = {
    
        val u = java.util.UUID.randomUUID
        val v = g.vertices.select("id")
    
    
        val vertexes: Array[String] = g.vertices.select("id").rdd.map(x => x(0).toString).collect()
    
        val edges: Array[Array[String]] = g.edges.select("src", "dst").rdd.map(r => Array(r(0).toString, r(1).toString)).collect()
    
        val edgeCreation = edges.map{ edgeArray =>
       "{source:nodes["+ vertexes.indexOf(edgeArray(0).trim()) +"],target:nodes["+ vertexes.indexOf(edgeArray(1).trim())+"]}"
      }
    
    
      println("""
        
         
         
         
         Graph
         
    """) }

提交回复
热议问题