【问题标题】:How to do that without dataset to rdd conversion?如何在没有数据集到 rdd 转换的情况下做到这一点?
【发布时间】:2023-03-14 19:57:01
【问题描述】:

有人可以帮助我如何避免 rdd 转换吗?

val qksDistribution: Array[((String, Int), Long)] = tripDataset
      .map(i => ((i.getFirstPoint.getQk.substring(0, QK_PARTITION_LEVEL), i.getProviderId), 1L))
      .rdd
      .reduceByKey(_+_)
      .filter(_._2>maxCountInPartition/10)
      .collect

【问题讨论】:

  • 可以使用groupByKey,然后通过reduce函数。无论如何,为什么要避免rdd 转换?
  • @LuisMiguelMejíaSuárez 因为我不太了解它是如何工作的,所以我预计在这种转换过程中会有很多对象分配
  • 能否提供地图返回的架构?
  • 是的,它可能会实例化一些东西,但我认为这不是什么大问题。无论如何,groupByKey 是您所需要的。

标签: scala apache-spark dataset rdd


【解决方案1】:
val qksDistribution: Array[((String, Int), Long)] = tripDataset
      .map(i => (i.getFirstPoint.getQk.substring(0, QK_PARTITION_LEVEL), i.getProviderId)) // no need to add the 1
      .groupByKey(x => x) //similar to key by
      .count // you wanted to count per key
      .filter(_._2>maxCountInPartition/10)
      .collect

【讨论】:

猜你喜欢
  • 2020-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-18
  • 2021-02-19
  • 1970-01-01
  • 1970-01-01
  • 2022-01-19
相关资源
最近更新 更多