0

How can I add different types of edges in the same graphX graph. For instance and edge between node A and node B may have String attribute and an edge between node X and node Y may have (Int, Int) attr.

Is there a way to implement edge inheritance in graphX? Can anyone provide an example?

Mayuri M.
  • 121
  • 1
  • 2

1 Answers1

0

The vertex and edge types of a graph are specified using the VD and ED type parameters on Graph. You can store different types of edge data on different edges as long as they share a common superclass. To do that, pass the common superclass as the ED type parameter when you construct the graph.

In your example, a common supertype of String and (Int, Int) is Any. You can construct a graph with edge attributes of both types like this:

val edges = List[Edge[Any]](
  Edge(1, 2, "foo"),
  Edge(3, 4, (123, 456)))

Graph.fromEdges(sc.parallelize(edges), 1)
Ankur Dave
  • 106
  • 4
  • further on this, if I have to use groupEdges on the same graph, how can that be done? – Mayuri M. Jul 18 '16 at 22:54
  • If I have a user defined edge attribute (say MySuperEdgeType) which can be subclassed into diff edgeTypes, then how would the grouping of Edges take place? trait MySuperEdge { def edgeType : String } case class SubEdge1( edType: String, totalCnt :Int) extends MySuperEdge{ def edgeType : String = { return edType } def edgeAttrValue : Int = { return totalCnt } } case class SubEdge2( edType: String, sales :Int, profit: Int, ) extends MySuperEdge{ def edgeType :String = {return edType } def val1 :Int = {return sales} def val2 :Int ={return profit} } – Mayuri M. Jul 18 '16 at 23:05
  • val baseGraph = Graph(nodes, edgeRDD) where edgeRDD is RDD of Edge[MySuperEdge] In this case, after graph creation, how would I groupEdges? – Mayuri M. Jul 18 '16 at 23:05