大数据全系列 教程
1869个小节阅读:467.2k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
package com.itbaizhan;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import java.io.IOException;
public class FOFDriver2 {
public static void main(String[] args) throws Exception {
if(args==null || args.length!=2){
System.out.println("Usage:yarn jar fof.jar com.itbaizhan.FOFDriver2 <inputPath> <outputPath>");
System.exit(1);
}
Configuration configuration = new Configuration(true);
configuration.set("mapreduce.framework.name","local");
Job job = Job.getInstance(configuration, "好友推荐MR2");
job.setJarByClass(FOFDriver2.class);
//设置InputFormatClass 将当前行文本中第一个\t之前的内容作为key,之后的内容作为value
job.setInputFormatClass(KeyValueTextInputFormat.class);
job.setMapperClass(FOFMapper2.class);
//cat hadoop,2
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setReducerClass(FOFReducer2.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job,new Path(args[0]));
Path outputPath = new Path(args[1]);
FileSystem fileSystem = FileSystem.get(configuration);
if(fileSystem.exists(outputPath)){
fileSystem.delete(outputPath,true);
}
FileOutputFormat.setOutputPath(job,outputPath);
job.waitForCompletion(true);
}
}