<version>1.7.30</version>
</dependency>
</dependencies>
2. 在项目的 src/main/resources 目录下,新建一个文件“log4j.properties”,在文
件中填入下列内容:
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=target/spring.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
3. 在项目的 src/main/java 目录下,新建一个包名 com.dh.mapreduce.wordcount,在该
包下创建三个 java 类 WordCountMapper、WordCountReducer、WordCountDriver。
4. 在 WordCountMapper 类中输入以下代码:
package com.dh.mapreduce;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
/**
* KEYIN,map 阶段输入的 key 类型 :LongWritable
* VALUEIN,map 阶段输入 value 类型:Text
* KEYOUT,map 阶段输出的 key 类型:Text
* VALUEOUT,map 阶段输出的 value 类型:IntWritable
*/
public class WordCountMapper extends Mapper<LongWritable, Text, Text,
IntWritable> {
Text outK = new Text();
private IntWritable outV = new IntWritable(1);
@Override
protected void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
//1、获取一行
String line = value.toString();
//2、对一行数据进行切割
String[] words = line.split(" ");
//3、循环写出
评论0
最新资源