In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
The editor will share with you the example analysis of NLineInputFormat. I hope you will get something after reading this article. Let's discuss it together.
Package com.test;import java.io.IOException;import java.util.Iterator;import java.util.StringTokenizer;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf.Configured;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.Mapper;import org.apache.hadoop.mapreduce.Reducer The data processed by import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.input.NLineInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;import org.apache.hadoop.util.Tool;import org.apache.hadoop.util.ToolRunner;/** * TextInputFormat comes from an InputSplit. InputSplit is divided according to block size. * because each record is long and short, the number of records processed by each map task varies * NLineInputFormat determines that the number of records processed by each map is the same * / public class WordCountNL extends Configured implements Tool {public static class Map extends Mapper {public void map (LongWritable key, Text value, Context context) throws IOException, InterruptedException {String line = value.toString (); StringTokenizer st = new StringTokenizer (line) While (st.hasMoreElements ()) {context.write (new Text (st.nextElement (). ToString ()), new IntWritable (1));} public static class Combiner extends Reducer {public void reduce (Text key, Iterable values, Context context) throws IOException, InterruptedException {int count = 0; Iterator it = values.iterator (); while (it.hasNext ()) {count = count + it.next (). Get ();} context.write (key, new IntWritable (count)) }} public static class Reduce extends Reducer {public void reduce (Text key, Iterable values, Context context) throws IOException, InterruptedException {int count = 0; Iterator it = values.iterator (); while (it.hasNext ()) {count = count + it.next (). Get ();} context.write (key, new IntWritable (count));} public int run (String [] args) throws IOException, InterruptedException, ClassNotFoundException {Configuration conf = this.getConf () / / set how many rows of data each map can handle / / conf.set ("mapreduce.input.lineinputformat.linespermap", "1"); conf.set (NLineInputFormat.LINES_PER_MAP, "1"); Job job = new Job (conf); job.setJobName (WordCountNL.class.getSimpleName ()); job.setJarByClass (WordCountNL.class); FileInputFormat.addInputPath (job, new Path (args [0])); FileOutputFormat.setOutputPath (job, new Path (args [1]) Job.setMapperClass (Map.class); job.setCombinerClass (Combiner.class); job.setReducerClass (Reduce.class); job.setInputFormatClass (NLineInputFormat.class); job.setOutputFormatClass (TextOutputFormat.class); job.setOutputKeyClass (Text.class); job.setOutputValueClass (IntWritable.class); job.waitForCompletion (true); return job.isSuccessful ()? 0V1;} public static void main (String [] args) throws Exception {int exit = ToolRunner.run (new WordCount (), args) System.exit (exit);}} after reading this article, I believe you have some understanding of "sample Analysis of NLineInputFormat". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.