gpt4 book ai didi

scala - 如何将 Dataset[(String, Seq[String])] 转换为 Dataset[(String, String)]?

转载 作者:行者123 更新时间:2023-12-04 17:54:30 25 4
gpt4 key购买 nike


可能这是一个简单的问题,但我从 spark 开始了我的冒险。

问题:我想在 spark 中获得以下结构(预期结果)。现在我有以下结构。

title1, {word11, word12, word13 ...}
title2, {word12, word22, word23 ...}

数据存储在Dataset[(String, Seq[String])]

异常结果我想得到 Tuple [word, title]

word11, {title1}
word12, {title1}

我做什么
1.制作(标题,seq[word1,word2,word,3])

docs.mapPartitions { iter =>
iter.map {
case (title, contents) => {
val textToLemmas: Seq[String] = toText(....)
(title, textToLemmas)
}
}
}
  1. 我尝试使用 .map 将我的结构转换为 Tuple,但做不到。
  2. 我试图遍历所有元素,但我无法返回类型

感谢您的回答。

最佳答案

这应该有效:

val result = dataSet.flatMap { case (title, words) => words.map((_, title)) }

关于scala - 如何将 Dataset[(String, Seq[String])] 转换为 Dataset[(String, String)]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44086100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com