资源简介
求所有文件中数值的最大三个值( Top 3 ),并按降序输出。MR编程mapper,reducer,combiner类的源代码
代码片段和文件信息
package com.top3;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
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;
public class TOP3 {
//@author YQ
public static class TopNMap extends Mapperject Text IntWritable NullWritable>{
private static IntWritable data = new IntWritable();
@Override
protected void map(object key Text valueContext context)
throws IOException InterruptedException {
//把字符串转为数值
data.set(Integer.parseInt(value.toString().trim()));
context.write(data NullWritable.get());
// System.out.println(data);
}
}
public static class TopNReducer extends Reducer{
private ArrayList keyList = new ArrayList();
private IntWritable num = new IntWritable();
@Override
public void reduce(IntWritable key Iterable values Context context) throws IOException InterruptedException {
//int kk = key.get();
keyList.add(key.get());
//System.out.println(kk);
}
@Override
protected void cleanup(Context context) throws IOException InterruptedException{
Collections.sort(keyList);//从
相关资源
- 用MapReduce开发的一个TFIDF 计算关键字
- hadoop实战源代码Java
- hadoop-2.6.0-hadoop.dll-winutils.exe
- 高职组云计算与大数据题库
- Hadoop-2.8.5全面资料
- IT18掌大数据课程包含配套资料
- wordcount.jar
- Hadoop-client-2.7.4.jar
- hadoop2.7.3 hadoop.dll
- hadoop2.7.1对应的hadoop.dllwinutils.exe等。
- Spark大数据中文分词统计Java工程源码
- hadoop-auth-2.2.0.jar
- hadoop-common-2.2.0-bin-master
- hive函数大全中文版
- hadoop.dll以及winutils.exe
- hadoop-lzo-0.4.13.jar
- 山东大学大数据实验三:Hadoop实现P
- hadoop-lzo-0.4.20-SNAPSHOT.jar 包
- hadoop-lzo-0.4.20-SNAPSHOT.jar
- 基于mapreduce的pagerank实现DEMO地址
- TFIDF算法mapreduce实现
- hadoop-lzo-0.4.20.jar
- Hive 入门级编程全案例详解
- hadoop-2.7.2-common.jar
- hadoop各版本--hadoop.dll以及winutils.exe,
- 2016年大数据全套视频徐培成
- hadoop-common-2.7.4-bin 包含hadoop.dll、win
- hadoop-core-1.2.1.jar
- 大数据hadoop winutils.exe
- Hadoop之MapReduce编程完整源码
评论
共有 条评论