我想根据文件名从 hadoop 中存在的文件列表中读取特定文件。如果文件名与我给定的名称匹配,我想处理该文件数据。这是我在 map 方法中尝试过的以下方法
public void map(LongWritable key,Text value,Context con) throws IOException, InterruptedException
{
FileSplit fs =(FileSplit) con.getInputSplit();
String filename= fs.getPath().getName();
filename=filename.split("-")[0];
if(filename.equals("aak"))
{
String[] tokens = value.toString().split("\t");
String name=tokens[0];
con.write(new Text("mrs"), new Text("filename"));
}
}
最佳答案
您需要编写自定义 PathFilter 实现,然后在驱动程序代码中对 FileInputFormat 使用 setInputPathFilter。请查看以下链接:
https://hadoopi.wordpress.com/2013/07/29/hadoop-filter-input-files-used-for-mapreduce/
关于hadoop - 从包含 hadoop 中许多文件的目录中读取特定文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27699815/