Search code examples
scalaapache-flinkgelly

Flink: Connected Components - type mismatch error


I am trying to run connected components algorithm on a graph using the Scala API as shown in the programming guide and other examples.

val graph = Graph.fromDataSet(vertices, edges, env).getUndirected
val maxIterations = 10
val components = graph.run(new ConnectedComponents(maxIterations))

And I get the following error:

Type mismatch, expected: GraphAlgorithm[Long,String,Long,NotInferedT], actual: ConnectedComponents[Nothing,Nothing]

And even if I add

val components = graph.run(new ConnectedComponents[Long,String,Long](maxIterations))

I get:

Type mismatch, expected: GraphAlgorithm[Long,String,Long,NotInferedT], actual: ConnectedComponents[Long,String]

My imports are these:

import org.apache.flink.api.scala._
import org.apache.flink.graph.library.ConnectedComponents
import org.apache.flink.graph.{Vertex, Edge}
import org.apache.flink.graph.scala.Graph

Can someone please explain why this is happening?


Solution

  • the ConnectedComponents Gelly library algorithm takes 2 type parameters, the vertex ID type and the edge value type, so you need to call it like this for example graph.run(new ConnectedComponents[Long, NullValue](maxIterations). Also, since it is a Java implementation, make sure to import java.lang.Long. You can also look at the org.apache.flink.graph.scala.example.ConnectedComponents which uses the GSA version of the library algorithm.