Search code examples
scalaspark-graphx

GraphX-Spark: error graph.vertices.filter


I am new in scala and spark-graphx. This is a method that I've written to extract the vertex that has min score value

def getMinScoreVertex(graph: Graph[(Int,Float,Float,Float,String),Float]):Float={
var minValue:Float=Float.PositiveInfinity
var LowestScoreValue=graph.vertices.filter { case (id,(_,_,_,Score,_)) => Score < minValue}
 return LowestScoreValue  }

I get the following error:

Error:(15, 62) constructor cannot be instantiated to expected type;
 found   : (T1, T2, T3, T4, T5)
 required: (org.apache.spark.graphx.VertexId, (Int, Float, Float, Float, String))
    (which expands to)  (Long, (Int, Float, Float, Float, String))
    var LowestScoreValue=graph.vertices.filter { case (_,_,_,Score,_) => Score < minValue}
Error:(15, 69) not found: value Score
    var LowestScoreValue=graph.vertices.filter { case (_,_,_,Score,_) => Score < minValue}
Error:(15, 82) not found: value Score
    var LowestScoreValue=graph.vertices.filter { case (_,_,_,Score,_) => Score < minValue}

Any ideas?? Thanks


Solution

  • At the commend I made a mistake, thinking Score is type. Most of time if you do pattern matching, it's safe to use lower-case letters. (lowercased variables in pattern matching)

    val filterResult = graph.vertices.filter {
        case (_, (_, _, _, score, _)) => score < minValue
    }
    

    This will not give compilation error.

    One more thing is filter is not the right choice to select the minimum choice. It'll just filter VertexRDD which has score less than minValue and will return list.