【发布时间】:2018-01-30 13:04:15
【问题描述】:
我之前问过这个问题,但不清楚,所以我添加了更多解释以更清楚并获得帮助。 replace strings with ZipWithIndex/ZipWithUniqueID
我正在尝试使用 ZipWithIndex 或 ZipWithUniqueID 将字符串映射到数字
假设我有这种格式
("u1",("name", "John Sam"))
("u2",("age", "twinty Four"))
("u3",("name", "sam Blake"))
我想要这个结果
(0,(3,4))
(1,(5,6))
(2,(3,8))
我尝试将 zipWithIndex 直接用于三元组,但我将每个字母映射到一个数字,我想映射整个字符串而不分割它。 并尝试提取键值对中的第一个元素 所以我做到了
val first = file.map(line=> line._1).distinct()
then apply ZipWithIndex
val z1= first.ZipWithIndex()
我得到了这样的结果
("u1",0)
("u2",1)
("u3",2)
现在我需要获取 ids/numbers 并在我的原始文件中进行更改。我需要将所有不同的 ids/numbers 保留在 hashTable 中,以便以后能够查找它们。 有什么办法吗?有什么建议吗?
希望你有我的问题
【问题讨论】:
-
我提到这是我之前的问题,但输入格式不同
标签: scala apache-spark