Selecting Faces in GraphFrames

I am using BFS using Graph frames in Scala. How to sum the weight of the edges of the selected shortest path. I have the following code:

    import org.graphframes._
    import org.apache.spark.sql.DataFrame
    val v = sqlContext.createDataFrame(List(
      ("1", "Al"),
      ("2", "B"),
      ("3", "C"),
      ("4", "D"),
      ("5", "E")
    )).toDF("id", "name")

    val e = sqlContext.createDataFrame(List(
      ("1", "3", 5),
      ("1", "2", 8),
      ("2", "3", 6),
      ("2", "4", 7),
      ("2", "1", 8),
      ("3", "1", 5),
      ("3", "2", 6),
      ("4", "2", 7),
      ("4", "5", 8),
      ("5", "4", 8)
    )).toDF("src", "dst", "property")
val g = GraphFrame(v, e)
val paths: DataFrame = g.bfs.fromExpr("id = '1'").toExpr("id = '5'").run()
paths.show()

OutPut above code:

+------+-------+-----+-------+-----+-------+-----+                              
|  from|     e0|   v1|     e1|   v2|     e2|   to|
+------+-------+-----+-------+-----+-------+-----+
|[1,Al]|[1,2,8]|[2,B]|[2,4,7]|[4,D]|[4,5,8]|[5,E]|
+------+-------+-----+-------+-----+-------+-----+

But I need a conclusion:

+----+-------+-----------+---------+
|    |source |Destination| Distance|
+----+-------+-----------+---------+
| e0 |   1    | 2        | 8       |
+----+-------+-----------+---------+
| e1 |   2    | 4        | 7       |
+----+-------+-----------+---------+
| e2 |   4    | 5        | 8       |
+----+-------+-----------+---------+

Unlike the example above, my graph is huge, it can actually return a large number of edges.

+4
source share

Source: https://habr.com/ru/post/1662760/


All Articles