In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces hadoop how to achieve two-color ball statistics, the article is very detailed, has a certain reference value, interested friends must read it!
1 / use hadoop to count the red balls adjacent to the two-color ball:
Test data can be found at: http://pan.baidu.com/s/1hq82YrU
Import java.io.IOException;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.List;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.NullWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Job Import org.apache.hadoop.mapreduce.Mapper;import org.apache.hadoop.mapreduce.Reducer;import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;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 / * mainly filter out two-color ball adjacent numbers * * / public class Adjacent extends Configured implements Tool {/ * counters * used to count all kinds of abnormal data * / enum Counter {LINESKIP / / Line in error} / * MAP Task * / public static class AdjacentMap extends Mapper {public void map (LongWritable key, Text value, Context context) throws IOException, InterruptedException {String line = value.toString () / / read source data: 2003001 10 11 12 13 26 28 11 line = line.replaceAll ("\ t", "") / / filter out tabs try {/ / data processing String [] lineSplit = line.split ("") If (lineSplit.length! = 8) {return } / / the last red ball is not judged here, because the last one will never have an adjacent ball String out = ""; int next =-1 List list = new ArrayList (); for (int item1)
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.