我想访问我的映射器中分布式文件的内容。以下是我编写的用于生成分布式缓存文件名称的代码。请帮我访问文件通过分布式缓存访问映射器中的文件
public class DistCacheExampleMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text >
{
Text a = new Text();
Path[] dates = new Path[0];
public void configure(JobConf conf) {
try {
dates = DistributedCache.getLocalCacheFiles(conf);
String astr = dates.toString();
a = new Text(astr);
} catch (IOException ioe) {
System.err.println("Caught exception while getting cached files: " +
StringUtils.stringifyException(ioe));
}
}
@Override
public void map(LongWritable key, Text value, OutputCollector<Text, Text> output,
Reporter reporter) throws IOException {
String line = value.toString();
for(Path cacheFile: dates){
output.collect(new Text(line), new Text(cacheFile.getName()));
}
}
}
我想要做的是我有一个文件,我传递给Mapper。我想比较该文件的每一行的第一列与分布式缓存文件。如果它存在于该文件中,我想将它传递给reducer否则不。 – Pooja3101
如何在您的文件中定义列?你想比较什么?分布式缓存中的整个文件? – vefthym
是的,我想比较整个文件。我想将csv文件添加到分布式缓存中,以便每个映射器都拥有它。请告诉我如何在我的映射器代码中将其作为csv文件读取。 – Pooja3101