DistributedCache使用

DistributedCache使用:

1.import包

import org.apache.hadoop.filecache.DistributedCache;

2.加到Cache中

DistributedCache.addCacheFile(new Path(args[++i]).toUri(), job.getConfiguration());

3.Map或Reduce中调用

Configuration conf = context.getConfiguration();

Path [] pathwaysFiles = new Path[0];

try {

pathwaysFiles = DistributedCache.getLocalCacheFiles(conf);

}catch (IOException ioe) {

System.err.println("Caught exception while getting cached files: " + StringUtils.stringifyException(ioe));

}

for (Path pathwaysFile : pathwaysFiles) {

try {

BufferedReader fis = new BufferedReader(new FileReader(pathwaysFile.toString()));

String pathway = null;

while ((pathway = fis.readLine()) != null) {

String [] p = pathway.split(" ");

pathways.add(p);

}

}catch (IOException ioe) {

}

}

DistributeCche的存储路径:

/ifshk4/HDFS/hadoop/hadoop12/tmp/mapred/local/taskTracker/archive/compute-7-0.local/user/hadoop/kipu/expression_head.txt/expression_head.txt

执行命令:

/tmp/hadoop/bin/hadoop jar kipu.jar org.bgi.kipu.kipu /user/hadoop/kipu/expression_final.txt /user/hadoop/kipu/output/ -pathways /user/hadoop/kipu/pathways_final.txt -head /user/hadoop/kipu/expression_head.txt


这个路径其实是当前map/reduce任务的本地路径再加上hdfs上的路径,

因此当然会跟执行任务时输入的参数不一致啦。

因此在DistributeCache中有多个文件的时候可以用以下方法判断:

1.将参数的内容放到conf中去:

job.getConfiguration().set("kipu.head.path", args[i]);

2.用contains来判断

pathwaysFile.toString().contains(conf.get("kipu.head.path"))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值