2024年4月1日发(作者:)

MapReduce第1关:成绩统计过关代码:

import ption;

import Tokenizer;

import ption;

import Tokenizer;

import uration;

import ;

import .*;

import ;

import ;

import ;

import r;

import putFormat;

import tputFormat;

import cOptionsParser;

public class WordCount {

Begin

public static class TokenizerMapper extends Mapper

{ private final static IntWritable one = new IntWritable(1);

private Text word = new Text();

private int maxValue = 0;

public void map(LongWritable key, Text value, Context context) throws IOException,

InterruptedException {

StringTokenizer itr = new StringTokenizer(ng(),"n");

while (eTokens()) {

String[] str = ken().split("");

String name = str[0];

(nt(str[1]));

(name);

(word,one);

)

//(word,one);

)

)

public static class IntSumReducer extends Reducer

{ private IntWritable result = new IntWritable();

public void reduce(Text key, Iterable values, Context context)

throws IOException, InterruptedException {

int maxAge = 0;

int age = 0;

for (IntWritable intWritable : values) {

maxAge = (maxAge, ());

)

(maxAge);

(key, result);

)

)

public static void main(String[] args) throws Exception {

Configuration conf = new Configuration();

Job job = new Job(conf, "word count");

ByClass();

perClass();

binerClass();

ucerClass();

putKeyClass();

putValueClass();

String inputfile = "/user/test/input";

String outputFile = "/user/test/output/";

utPath(job, new Path(inputfile));

putPath(job, new Path(outputFile));

rCompletion(true);

End

)

)

命令行

touch file01 echo Hello World Bye World

cat file01

echo Hello World Bye World >file01

cat file01

touch file02

echo Hello Hadoop Goodbye Hadoop >file02 cat file02

hadoop fs -mkdir /usr

hadoop fs -mkdir /usr/input

hadoop fs -ls /usr/output

hadoop fs -ls /

hadoop fs -ls /usr

hadoop fs -put file01 /usr/input

hadoop fs -put file02 /usr/input

hadoop fs -ls /usr/input

测评

MapReduce第2关:文件内容合并去重代码

import ption;

import .*;

import uration;

import ;

import .*;

import ;