using hadoop 0.20.2 and trying to read a serialized map via distributed cache
facing a compilation error localFiles = DistributedCache.getLocalCacheFiles(job); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unhandled exception type IOException
DRIVER Class snippet (/scratch/word_id.ser is a serialized file stored in local system)
Job job = new Job(conf, "xml-read");
DistributedCache.addCacheFile(new URI("/scratch/word_id.ser"),job);
MAPPER Class snippet
public class MyParserMapper1 {
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, IntWritable, Text> {
private FileSystem fs;
private Path[] localFiles;
HashMap hash_temp;
private ObjectInputStream oisc;
@Override
public void configure(JobConf job) {
localFiles = DistributedCache.getLocalCacheFiles(job);
}
Your IDE probably has some auto-fix rules for things like this, but anyway, you need to wrap the statement in a try / catch block:
@Override
public void configure(JobConf job) {
try {
localFiles = DistributedCache.getLocalCacheFiles(job);
} catch (IOException ioe) {
throw new RuntimException(ioe);
}
}
If you can handle the exception all the better (ie if you can still run your mapper without this file), but otherwise just wrap in an unchecked exception like RuntimeException
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.