【问题标题】:Why can't I use combineByKey in Spark?为什么我不能在 Spark 中使用 combineByKey?
【发布时间】:2021-02-06 05:58:46
【问题描述】:

我在 Spark 2.4.5 中编写此代码:

df_join is a dataframe.    

var comByKeyResult: Dataset[((String, String), (Double, Int))] = df_join
      .map(x => ((x(1).toString, x(3).toString), (x(9).toString.toDouble, x(1).toString.toInt)))

当我尝试编写comByKeyResult.combineByKey, 时,combineByKey 方法不可用。为什么?

我导入了以下库:import org.apache.spark.rdd._。我是否必须添加其他库或包?

【问题讨论】:

    标签: scala apache-spark rdd


    【解决方案1】:

    combineByKey是对PairRDD的变换操作

    您需要将数据框/数据集转换为rdd,然后将其映射到pairRdd 在你的情况下,只是一个小改动:

    val yourPairRdd = df_join
    .rdd
    .map(x => ((x(1).toString, x(3).toString), (x(9).toString.toDouble, x(1).toString.toInt)))
    
    //yourPairRdd.combineByKey
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 2017-03-05
      相关资源
      最近更新 更多