Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize two-color sphere statistics by hadoop

Shulou Source: shulou.com Published: 2022-05-31 21:31:39 10月05日 Update

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)

Tags: Tasks output data two-color two-color ball statistics parameters format counter path input run success number code content tabs name situation data processing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Shulou Tech Info Redmi Microsoft