gpt4 book ai didi

java - 在 MapReduce 中读取文件的问题

转载 作者:可可西里 更新时间:2023-11-01 15:55:59 26 4
gpt4 key购买 nike

在使用 hadoop 1.1.2 的 map reduce 作业中,我一直无法从文件中读取其路径由用户提供的内容。下面的代码是我一直在尝试使用的代码,但是在读取文件内容时,我总是得到 null。我在这里遇到了一些解决方案,但没有一个对我有用:

主要功能:

    Job job = new Job (conf, "Find K-Nearest Neighbour");
job.setJarByClass(Knn.class);
DistributedCache.addCacheFile(new Path("knnParamFile").toUri(), con);

映射器类(设置函数):

    Configuration conf = context.getConfiguration();

if (DistributedCache.getCacheFiles(conf) != null && DistributedCache.getCacheFiles(conf).length > 0)
{

String knnParams = FileUtils.readFileToString(new File("./knnParamFile"));
// rest of logic
}

任何想法或建议将不胜感激

最佳答案

请在以下位置找到工作代码

http://bytepadding.com/big-data/map-reduce/map-side-joins-in-map-reduce/

please use  job.addCacheFile(inputPathDistributed.toUri());

在分布式缓存中添加文件

关于java - 在 MapReduce 中读取文件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43925637/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com