Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo equal combine keys do not get to the same reducer
    primarykey
    data
    text
    <p>I'm making a Hadoop application in Java with the MapReduce framework.</p> <p>I use only Text keys and values for both input and output. I use a combiner to do an extra step of computations before reducing to the final output.</p> <p>But I have the problem that the keys do not go to the same reducer. I create and add the key/value pair like this in the combiner: </p> <pre><code>public static class Step4Combiner extends Reducer&lt;Text,Text,Text,Text&gt; { private static Text key0 = new Text(); private static Text key1 = new Text(); public void reduce(Text key, Iterable&lt;Text&gt; values, Context context) throws IOException, InterruptedException { key0.set("KeyOne"); key1.set("KeyTwo"); context.write(key0, new Text("some value")); context.write(key1, new Text("some other value")); } } public static class Step4Reducer extends Reducer&lt;Text,Text,Text,Text&gt; { public void reduce(Text key, Iterable&lt;Text&gt; values, Context context) throws IOException, InterruptedException { System.out.print("Key:" + key.toString() + " Value: "); String theOutput = ""; for (Text val : values) { System.out.print("," + val); } System.out.print("\n"); context.write(key, new Text(theOutput)); } } </code></pre> <p>In the main i creates the job like this:</p> <pre><code>Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); Job job4 = new Job(conf, "Step 4"); job4.setJarByClass(Step4.class); job4.setMapperClass(Step4.Step4Mapper.class); job4.setCombinerClass(Step4.Step4Combiner.class); job4.setReducerClass(Step4.Step4Reducer.class); job4.setInputFormatClass(TextInputFormat.class); job4.setOutputKeyClass(Text.class); job4.setOutputValueClass(Text.class); FileInputFormat.addInputPath(job4, new Path(outputPath)); FileOutputFormat.setOutputPath(job4, new Path(finalOutputPath)); System.exit(job4.waitForCompletion(true) ? 0 : 1); </code></pre> <p>The output in stdout printed from the reducer is this:</p> <pre><code>Key:KeyOne Value: ,some value Key:KeyTwo Value: ,some other value Key:KeyOne Value: ,some value Key:KeyTwo Value: ,some other value Key:KeyOne Value: ,some value Key:KeyTwo Value: ,some other value </code></pre> <p>Which makes no sense since the keys are the same, and therefore it should be 2 reducers with 3 of the same values in it's Iterable</p> <p>Hope you can help me get to the bottom of this :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload