【问题标题】:Spark error: missing parameter type in map()Spark 错误:map() 中缺少参数类型
【发布时间】:2017-08-20 00:09:48
【问题描述】:

我正在尝试通过复制code here 在 Windows 10 上学习 Spark GraphX。该代码是使用旧版本的 Spark 开发的,我无法找到创建顶点的解决方案。以下是代码

import scala.util.MurmurHash
import org.apache.spark._
import org.apache.spark.graphx._
import org.apache.spark.rdd.RDD

val path = "F:/Soft/spark/2008.csv"
val df_1 = spark.read.option("header", true).csv(path)

val flightsFromTo = df_1.select($"Origin",$"Dest")
val airportCodes = df_1.select($"Origin", $"Dest").flatMap(x => Iterable(x(0).toString, x(1).toString))

// error caused by the following line
val airportVertices: RDD[(VertexId, String)] = airportCodes.distinct().map(x => (MurmurHash.stringHash(x), x))

以下是错误信息:

<console>:57: error: missing parameter type
       val airportVertices: RDD[(VertexId, String)] = airportCodes.distinct().map(x => (MurmurHash.stringHash(x), x))
                                                                                  ^

我认为语法已经过时,我试图在official documents 上找到最新的语法,但没有任何帮助。数据集可以从here下载。

更新:

基本上,我正在尝试创建一个顶点和边,最终创建一个图,如tutorial 所示。我也是 Map-Reduce 范式的新手。

【问题讨论】:

    标签: scala apache-spark spark-graphx


    【解决方案1】:

    您可以尝试: val airportVertices: RDD[(VertexId, String)] = airportCodes.distinct().map(x => (MurmurHash.stringHash(x(0)), x(1)))

    【讨论】:

    • 它仍然给出同样的错误:&lt;console&gt;:37: error: missing parameter type val airportVertices: RDD[(VertexId, String)] = airportCodes.distinct().map(x =&gt; (MurmurHash.stringHash(x(0)), x(1)))
    【解决方案2】:

    以下代码行对我有用。

    // imported latest library - works without this too, just gives a warning
    import scala.util.hashing.MurmurHash3
    
    // datasets are set to rdd - this is the cause of the error
    val flightsFromTo = df_1.select($"Origin",$"Dest").rdd
    val airportCodes = df_1.select($"Origin", $"Dest").flatMap(x => Iterable(x(0).toString, x(1).toString)).rdd
    
    val airportVertices: RDD[(VertexId, String)] = airportCodes.distinct().map(x => (MurmurHash3.stringHash(x), x))
    

    【讨论】:

      【解决方案3】:

      // 为了应用 map(),只需尝试将变量转换为 RDD。

      val airportVertices: RDD[(VertexId, String)] = airportCodes.rdd.distinct().map(x => (MurmurHash3.stringHash(x), x))

      【讨论】:

        猜你喜欢
        • 2017-06-23
        • 2018-03-28
        • 2012-02-23
        • 2017-03-18
        • 2021-04-22
        • 1970-01-01
        • 2012-10-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多