【发布时间】:2017-10-18 02:57:18
【问题描述】:
我读到reducebyKey 是大型数据集的更好选择,可以减少数据的混洗,从而提高性能。
我正在尝试转换我对groupByKey 的使用。首先它必须被转换为 rdd 为:
val linksNew = links.map(convertToRelationship)
.flatMap(bidirRelationship)
links 是一个数据集,而数据集 api 没有 reduceByKey。当使用reduceByKey 时,.groupByKey(_._1) 的等价物是什么?
val linksfinal = linksNew.rdd.reduceByKey(???)
实际代码:
val biLinks = links
.map(convertToRelationship)
.flatMap(bidirRelationship)
.groupByKey(_._1)
.reduceGroups((left, right) => combineBidirerRelationships(left,right))
.map(_._2._2)
数据集的架构,就在使用groupByKey(_._1)之前:
数据集中的一些实际数据:
【问题讨论】:
-
您的数据在
groupByKey()之前的样子如何? -
@Shaido 像这样
DataSet(String, Relationship)然后应该跟 groupByKey 一样,KeyValueGroupedDataSet[String, (String, Relationship)] -
添加了一个我相信会起作用的答案,虽然我没有测试它,告诉我它是如何工作的。
-
@Shaido 添加了一张图片,这两个添加了,
col1: String, col2: Relationship当我打印我们要转换的架构时,它们是struct1和struct2,例如struct2 是一个数据创建的关系案例类 -
你能把
show()的输出也加进去吗?
标签: scala apache-spark spark-dataframe rdd