我讀了reducebyKey
對大數據集來說是一個更好的選擇,可以減少數據的混洗,並以這種方式提高性能。我想轉換我的使用groupByKey
。首先,它必須被轉換爲RDD:將groupByKey轉換爲reduceByKey
val linksNew = links.map(convertToRelationship)
.flatMap(bidirRelationship)
鏈接是一個數據集和數據集的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()'之前的樣子是怎麼樣的? – Shaido
@Shaido喜歡這樣''DataSet(String,Relationship)'然後應該如下 with groupByKey跟着,'KeyValueGroupedDataSet [String,(String,Relationship)]' – dedpo
添加一個我相信會工作的答案,儘管我沒有'對它進行測試,告訴我它是如何工作的。 – Shaido