【发布时间】:2018-07-05 00:38:40
【问题描述】:
我正在尝试使用 ZipWithIndex 或 ZipWithUniqueID 将某个字符串替换为数字
假设我有这种格式
("u1",("name", "John Sam"))
("u2",("age", "twinty Four"))
("u3",("name", "sam Blake"))
我想要这个结果
(0,(3,4))
(1,(5,6))
(2,(3,8))
我所做的是提取键值对中的第一个元素 所以我做到了
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