使用MapReduce统计TopN数据

前几天做了一个实验,把实验报告贴这吧。

部分实验数据:

使用MapReduce统计TopN数据_第1张图片

使用MapReduce统计TopN数据_第2张图片

一、实验目的

学习和掌握利用MapReduce进行数据分析,加深对所学知识点的理解,熟悉MapReduce的数据处理流程。

二、实验内容

使用Hadoop生态组件(文件系统HDFS,处理引擎MapReduce),基于机票销售记录数据集,完成特定数据分析任务。
1、统计在买入方和卖出方出现次数最多的机场Top10;
2、统计买票数卖票数综合最多的代理人Top10;
3、统计第一天卖出票最多的机场Top10。

三、实验步骤

实验代码如下:

package MR;

import java.io.IOException;
import java.util.TreeMap;
import java.util.Comparator;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;



public class T1 {
   
	public static class Map extends Mapper<LongWritable, Text, Text, IntWritable>{
   
		
		public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{
   
			String line = value.toString();
			String str[] = line.split(",");
			// to avoid ArrayIndexOfBoundException
			if (str.length > 4){
   
				// consider sale
				// if it's the 1st day
				if (str[0].equals("01")){
   
					// to solve the 3rd question
					if (str[1].matches("C\\d+")) context.write(new Text(str[1] + "Sold"), new IntWritable(Integer.parseInt

你可能感兴趣的:(hadoop,大数据,mapreduce,数据结构)