java - How to sort word count program by value or count? -


How can I sort my password output based on the count / value of the key?

In the general case, the output is

  Hi 2 hw 3 wr1 r 3   

but the desired output is < pre> wr 1 hi 2 hw 3 r 3

My code is:

  Public class sorting application {applies the public static class map MapReduceBase Mapper & lt; Longweightable, text, intrite, text & gt; {Private Final Static IntWritable A = New IntWritable (1); Private text word = new text (); Public Zero Maps (LongWritable Key, Text Value, OutputCollector & LT; IntWritable, Text & Production; Report, Reporter Correspondent) throws IOException {string line = value.toString (); StringTokenizer Tokenizer = New String Toner (Line); While (tokenizer.hasMoreTokens ()) {word.set (tokenizer.nextToken ()); output.collect (one, word); }}} Expand declines in public static class MapReduceBase applies Reducer & lt; IntWritable, Text, IntWritable, Text & gt; {The public throws down zero (Iterator & lt; IntWritable> Key, Text value, OutputCollector & lt; IntWritable, Text & product; Production, Reporter Correspondent) IOException {int tot = 0; While (key.hasNext ()) {sum + = key.next (). Get (); } Output.collect (new IntWritable (sum), value); } @Override throws public at zero (IntWritable arg0, Iterator & lt; text & gt; ARG1, OutputCollector & lt; IntWritable, text & gt; ARG2, Reporter arg3) IOException {// TODO Automatic Created Method Stub}} Public Static Class GroupComparator extends WritableComparator {Protected GroupComparator () {Super (IntWritable.class, true); } @SuppressWarnings ("rawtypes") @Override Public Integer Comparison (WritableComparable w1, WritableComparable W2) {IntWritable v1 = (IntWritable) w1; IntWritable v2 = (IntWritable) w2; Return -1 * v1.compareTo (v2); }} Public static zero master (string [] args) throws exception {JobConf conf = new JobConf (sortingprog.class); conf.setJobName ("wordcount"); Conf.setOutputKeyClass (IntWritable.class); Conf.setOutputValueClass (Text.class); conf.setMapperClass (Map.class); Conf.setReducerClass (Reduce.class); conf.setOutputValueGroupingComparator (GroupComparator.class); conf.setInputFormat (TextInputFormat.class); conf.setOutputFormat (TextOutputFormat.class); FileInputFormat.setInputPaths (conf, new path (args [0])); FileOutputFormat.setOutputPath (conf, new path (args [1])); JobClient.runJob (conf); }}    

what you see is called "secondary order" here you two Find out how to reduce a value in your MapReduce:



Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -