将 TreeSet 存储在 Hadoop DistributedCache 上

soc*_*oho 5 java serialization hadoop mapreduce distributed-cache

我正在尝试将 a 存储TreeSet在 a 上,DistributedCache以供 Hadoop 映射缩减作业使用。到目前为止,我已经将文件从 HDFS 添加到DistributedCache

Configuration conf = new Configuration();
DistributedCache.addCacheFile(new URI("/my/cache/path"), conf);
Job job = new Job(conf, "my job");
// Proceed with remainder of Hadoop map-reduce job set-up and running
Run Code Online (Sandbox Code Playgroud)

如何有效地将 TreeSet(我已经在此类中构建)添加到我要添加到 DistributedCache 的文件中?我应该使用 Java 的本机序列化以某种方式将其序列化到文件中吗?

请注意,TreeSet 在启动 Map-Reduce 作业的主类中构建一次。TreeSet 永远不会被修改,我只是希望每个映射器都可以只读访问此 TreeSet,而不必一遍又一遍地重建它。

Rag*_*ags 1

序列化 TreeSet 似乎是一种方法。在这种情况下,您不需要创建 HashMap。只需从文件中反序列化 TreeSet 并使用方法根据键进行搜索即可。我喜欢这种方法。