title: How do I access DistributedCache in Hadoop Map/Reduce jobs?
body: <p>I'm trying to pass a small file to a job I'm running using the <code>GenericOptionsParser</code>'s <code>-files</code> flag:</p>
  
  <pre><code>$ hadoop jar MyJob.jar -conf /path/to/cluster-conf.xml -files /path/to/local-file.csv data/input data/output
  </code></pre>
  
  <p>This is supposed to send the job to my cluster and attach the local-file.csv to be available to the Mapper/Reducer when needed. It worked great when I ran this in pseudo distributed mode, but when I launch the job on the cluster it seems the file cannot be found. I'm reading the file in my mapper's <code>setup</code> method like so:</p>
  
  <pre><code>public static class TheMapper extends Mapper&lt;LongWritable, Text, Text, Text&gt; {
  
    @Override
    public void setup(Context context) throws IOException, InterruptedException {
  
      URI[] uriList = DistributedCache.getCacheFiles( context.getConfiguration() );
      CsvReader csv = new CsvReader(uriList[0].getPath());
  
      // work with csv file..
    }
  
    // ..
  }
  </code></pre>
  
  <p>When the job is running, I get the following exception:</p>
  
  <pre><code>java.io.FileNotFoundException: File /hdfs/tmp/mapred/staging/hduser/.staging/job_201205112311_011/files/local-file.csv does not exist.
  at com.csvreader.CsvReader.&lt;init&gt;(Unknown Source)
  at com.csvreader.CsvReader.&lt;init&gt;(Unknown Source)
  at com.csvreader.CsvReader.&lt;init&gt;(Unknown Source)
  at MyJob$TheMapper.setup(MyJob.java:167)
  at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:142)
  ...
  </code></pre>
  
  <p>Any idea what I'm doing wrong? thanks.</p>