title: Find the sales breakdown by product category across all of our stores
body: <p>I have a sales file with information such as store name, location, sales price, product name etc. The format for the file is provided below,</p>
  
  <pre><code>2012-01-01  09:00   San Jose    Men's Clothing  214.05  Amex
  2012-01-01  09:00   Fort Worth  Women's Clothing    153.57  Visa
  2012-01-01  09:00   San Diego   Music   66.08   Cash
  2012-01-01  09:00   Pittsburgh  Pet Supplies    493.51  Discover
  2012-01-01  09:00   Omaha   Children's Clothing 235.63  MasterCard
  2012-01-01  09:00   Stockton    Men's Clothing  247.18  MasterCard  
  </code></pre>
  
  <p>I would like to write a Map-reduce job to find the sales breakdown by product category across all of our stores. My code (including the Mapper and reducer) is provided below, </p>
  
  <pre><code>public final class P1Q1 {
  
  
      public static final class P1Q1Map extends Mapper&lt;LongWritable, Text, Text, DoubleWritable&gt; {
  
          private final Text word = new Text();
  
          public final void map(final LongWritable key, final Text value, final Context context)
                  throws IOException, InterruptedException {
  
              final String line = value.toString();
              final String[] data = line.trim().split("\t");
  
              if (data.length == 6) {
  
                  final String product = data[3];
                  final double sales = Double.parseDouble(data[4]);
  
                  word.set(product);
                  context.write(word, new DoubleWritable(sales));
              }
          }
      }
  
  
      public static final class P1Q1Reduce extends Reducer&lt;Text, DoubleWritable, Text, DoubleWritable&gt; {
  
          public final void reduce(final Text key, final Iterable&lt;DoubleWritable&gt; values, final Context context)
                  throws IOException, InterruptedException {
  
              double sum = 0.0;
  
              for (final DoubleWritable val : values) {
                  sum += val.get();
              }
  
              context.write(key, new DoubleWritable(sum));
          }
      }
  
  
      public final static void main(final String[] args) throws Exception {
  
  
          final Configuration conf = new Configuration();
  
          final Job job = new Job(conf, "P1Q1");
          job.setJarByClass(P1Q1.class);
  
          job.setOutputKeyClass(Text.class);
          job.setOutputValueClass(DoubleWritable.class);
  
          job.setMapperClass(P1Q1Map.class);
          job.setCombinerClass(P1Q1Reduce.class);
          job.setReducerClass(P1Q1Reduce.class);
  
          job.setInputFormatClass(TextInputFormat.class);
          job.setOutputFormatClass(TextOutputFormat.class);
  
          FileInputFormat.addInputPath(job, new Path(args[0]));
          FileOutputFormat.setOutputPath(job, new Path(args[1]));
  
          job.waitForCompletion(true);
      }
  }
  </code></pre>
  
  <p>The answer the code provides is not correct and doesn't match with the Udacity results. </p>
  
  <p>Anyone knows if this the correct thought and how to do that?</p>
  
  <p>Note</p>
  
  <ol>
  <li><p>I get a completely wrong result in the output file,</p>
  
  <pre><code>Baby    5.749180844000035E7
  Books   5.745075790999787E7
  CDs 5.741075304000156E7
  Cameras 5.7299046639999785E7
  Children's Clothing 5.762482094000117E7
  Computers   5.7315406319999576E7
  Consumer Electronics    5.745237412999948E7
  Crafts  5.7418154499999225E7
  DVDs    5.764921213999939E7
  Garden  5.7539833110000335E7
  Health and Beauty   5.748158956000019E7
  Men's Clothing  5.76212790400011E7
  Music   5.749548970000038E7
  Pet Supplies    5.71972502400004E7
  Sporting Goods  5.7599085889999546E7
  Toys    5.746347710999843E7
  Video Games 5.7513165580000155E7
  Women's Clothing    5.74344489699993E7
  </code></pre></li>
  <li><p>I thought if the comment out the combiner, this will be okay. I did that and doesn't change the result. </p>
  
  <pre><code> job.setCombinerClass(P1Q1Reduce.class);
  </code></pre></li>
  <li><p>I provided the code and the <code>purchases.txt</code> file link is <a href="https://drive.google.com/open?id=1dygPQozVOwA_uROI10mQJkCoZvE7-KD1" rel="nofollow noreferrer">here</a>. If anyone tries to solve the problem and successful to submit in the <a href="https://classroom.udacity.com/courses/ud617/lessons/313947755/concepts/24650686840923" rel="nofollow noreferrer">Udacity</a>, please, let me know. </p></li>
  </ol>