【发布时间】:2018-11-26 18:32:11
【问题描述】:
我有输入数据:
time, id, counter, value
00.2, 1 , c1 , 0.2
00.2, 1 , c2 , 0.3
00.2, 1 , c1 , 0.1
我希望为每个 id 创建一个结构来存储计数器和值。在考虑了向量并拒绝它们之后,我得出了这个结论:
(id, Hashmap( (counter1, List(Values)), (Counter2, List(Values)) ))
(1, HashMap( (c1,List(0.2, 0.1)), (c2,List(0.3)))
问题是我无法在映射转换中转换为 Hashmap,另外我不知道是否可以通过计数器减少映射中的列表。
有人知道吗?
我的代码是:
val data = inputRdd
.map(y => (y(1).toInt, mutable.HashMap(y(2), List(y(3).toDouble)))).reduceByKey(_++_)
}
【问题讨论】:
-
为什么 RDD API 不是 DataFrame/Dataset?!
标签: scala list apache-spark hashmap