运行hadoop程序,如何在map中获取输入数据的全路径(fullpath)

可以利用override map函数的第三个参数。map函数如下:
public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter)

String path = ((FileSplit) reporter.getInputSplit()).getPath().toString();   

即可取得全路径。

 

下面这个方法可以做文件选取:

public class Filter implements PathFilter {
     
public boolean accept(Path path) {
       
return !(path.toString().indexOf("abc") > -1);  
      }
}

jobConf .set( "mapred.input.pathFilter.class" , "Filter" );

org.apache.hadoop.fs
Interface PathFilter

All Known Implementing Classes:
OutputLogFilter

public interface PathFilter
 

 


Method Summary
booleanaccept(Path path)
           Tests whether or not the specified abstract pathname should be included in a pathname list.

Method Detail

accept

boolean accept(Path path)
Tests whether or not the specified abstract pathname should be included in a pathname list.

 

Parameters:
path - The abstract pathname to be tested
Returns:
true if and only if pathname should be included

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值