从DistributedCache Hadoop中的序列文件中读取

时间:2015-05-11 15:05:19

标签: hadoop

如何从分布式缓存中读取序列文件?

我尝试了一些东西,但我总是得到FileNotFoundException。

我正在将文件添加到分布式缓存中,如此

DistributedCache.addCacheFile(new URI(currentMedoids), conf);

在mapper的设置方法中读取它

        Configuration conf = context.getConfiguration();
        FileSystem fs = FileSystem.get(conf);

        Path[] paths = DistributedCache.getLocalCacheFiles(conf);

        List<Element> sketch = new ArrayList<Element>();

        SequenceFile.Reader medoidsReader = new SequenceFile.Reader(fs, paths[0], conf);

        Writable medoidKey = (Writable) medoidsReader.getKeyClass().newInstance();
        Writable medoidValue = (Writable) medoidsReader.getValueClass().newInstance();

        while(medoidsReader.next(medoidKey, medoidValue)){

            ElementWritable medoidWritable = (ElementWritable)medoidValue;
            sketch.add(medoidWritable.getElement());
        }

1 个答案:

答案 0 :(得分:0)

似乎我应该使用getCacheFiles(),它返回URI []而不是getLocalCacheFiles(),它返回Path []。

现在它可以在做出改变之后发挥作用。

相关问题