我想訪問我的映射器中分佈式文件的內容。以下是我編寫的用於生成分佈式緩存文件名稱的代碼。請幫我訪問文件通過分佈式緩存訪問映射器中的文件
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