可能这是一个简单的问题,但我正在开始我的spark之旅。
问题:我想在spark中获得以下结构(预期结果)。现在我有以下结构。
title1,{word11,word12,word13 ...}
title2,{word12,word22,word23 ...}
数据存储在Dataset [(String,Seq [String])]中。
预期结果 我想要得到Tuple [word,title]
word11,{title1}
word12,{title1}
我该怎么做
1. 创建(title,seq[word1,word2,word,3])
docs.mapPartitions { iter =>
iter.map {
case (title, contents) => {
val textToLemmas: Seq[String] = toText(....)
(title, textToLemmas)
}
}
}
- 我尝试使用.map将我的结构转换为元组,但无法实现。
- 我尝试遍历所有元素,但是这样我就无法返回类型。
谢谢您的回答。