当前位置:   article > 正文

MapReduce编程_现有一组数据input.txt,内容如下所示,请编写mapreduce程序提取出最大的5个数据,并

现有一组数据input.txt,内容如下所示,请编写mapreduce程序提取出最大的5个数据,并

实验目的(转载地址

  1. 通过实验掌握基本的MapReduce编程方法。
  2. 掌握用MapReduce解决一些常见的数据处理问题,包括数据去重、数据排序和数据挖掘等。
  3. 通过操作MapReduce的实验,模仿实验内容,深入理解MapReduce的过程,熟悉MapReduce程序的编程方式。

实验平台

  • 操作系统:Ubuntu-16.04
  • Hadoop版本:2.6.0
  • JDK版本:1.8
  • IDE:Eclipse

实验内容和要求

一,编程实现文件合并和去重操作:

  1. 对于两个输入文件,即文件A和文件B,请编写MapReduce程序,对两个文件进行合并,并剔除其中重复的内容,得到一个新的输出文件C。下面是输入文件和输出文件的一个样例供参考。
  • 输入文件f1.txt的样例如下:
  1. 20150101 x
  2. 20150102 y
  3. 20150103 x
  4. 20150104 y
  5. 20150105 z
  6. 20150106 x
  • 输入文件f2.txt的样例如下:
  1. 20150101 y
  2. 20150102 y
  3. 20150103 x
  4. 20150104 z
  5. 20150105 y
  • 根据输入文件f1和f2合并得到的输出文件的样例如下:
  1. 20150101 x
  2. 20150101 y
  3. 20150102 y
  4. 20150103 x
  5. 20150104 y
  6. 20150104 z
  7. 20150105 y
  8. 20150105 z
  9. 20150106 x

实验过程:

  1. 创建文件f1.txt和f2.txt


    将上面样例内容复制进去
  2. 在HDFS建立input文件夹(执行这步之前要开启hadoop相关进程)


  3. 上传样例到HDFS中的input文件夹


  4. 接着打开eclipse
    Eclipse的使用
    1. 点开项目,找到 src 文件夹,右键选择 New -> Class


    2. 输入 Package 和 Name,然后Finish


    3. 写好Java代码(给的代码里要修改HDFS和本地路径),右键选择 Run As -> Run on Hadoop,结果在HDFS系统中查看


实验代码:

  1. package cn.edu.zucc.mapreduce;
  2. import java.io.IOException;
  3. import org.apache.hadoop.conf.Configuration;
  4. import org.apache.hadoop.fs.Path;
  5. import org.apache.hadoop.io.Text;
  6. import org.apache.hadoop.mapreduce.Job;
  7. import org.apache.hadoop.mapreduce.Mapper;
  8. import org.apache.hadoop.mapreduce.Reducer;
  9. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  10. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  11. public class Merge {
  12. public static class Map extends Mapper<Object, Text, Text, Text> {
  13. private static Text text = new Text();
  14. @Override
  15. public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
  16. text = value;
  17. context.write(text, new Text(""));
  18. }
  19. }
  20. public static class Reduce extends Reducer<Text, Text, Text, Text> {
  21. @Override
  22. public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
  23. context.write(key, new Text(""));
  24. }
  25. }
  26. public static void main(String[] args) throws Exception {
  27. Configuration conf = new Configuration();
  28. conf.set("fs.defaultFS", "hdfs://localhost:9000");
  29. String[] otherArgs = new String[]{"input", "output"};
  30. if (otherArgs.length != 2) {
  31. System.err.println("Usage: Merge and duplicate removal <in> <out>");
  32. System.exit(2);
  33. }
  34. Job job = Job.getInstance(conf, "Merge");
  35. job.setJarByClass(Merge.class);
  36. job.setMapperClass(Map.class);
  37. job.setReducerClass(Reduce.class);
  38. job.setOutputKeyClass(Text.class);
  39. job.setOutputValueClass(Text.class);
  40. FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  41. FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  42. System.exit(job.waitForCompletion(true) ? 0 : 1);
  43. }
  44. }
模仿上题完成以下内容:对于两个输入文件,即文件A和文件B,请编写MapReduce程序,对两个文件进行统计单词数量,得到一个新的输出文件C。下面是输入文件和输出文件的一个样例供参考。
  • 输入文件a.txt的样例如下:
  1. hello world
  2. wordcount java
  3. android hbase
  4. hive pig
  • 输入文件b.txt的样例如下:
  1. hello hadoop
  2. spring mybatis
  3. hive hbase
  4. pig android
  • 输出文件的结果为:
  1. android 2
  2. hadoop 1
  3. hbase 2
  4. hello 2
  5. hive 2
  6. java 1
  7. mybatis 1
  8. pig 2
  9. spring 1
  10. wordcount 1
  11. world 1

实验代码:

  1. package cn.edu.zucc.mapreduce;
  2. import java.io.IOException;
  3. import org.apache.hadoop.conf.Configuration;
  4. import org.apache.hadoop.fs.Path;
  5. import org.apache.hadoop.io.IntWritable;
  6. import org.apache.hadoop.io.Text;
  7. import org.apache.hadoop.mapreduce.Job;
  8. import org.apache.hadoop.mapreduce.Mapper;
  9. import org.apache.hadoop.mapreduce.Reducer;
  10. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  11. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  12. public class WordCount {
  13. public static class Map extends Mapper<Object, Text, Text, IntWritable> {
  14. private static final IntWritable one = new IntWritable(1);
  15. private Text word = new Text();
  16. @Override
  17. public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
  18. String lineValue = value.toString();
  19. String[] words = lineValue.split(" ");
  20. for (String singleWord : words) {
  21. word.set(singleWord);
  22. context.write(word, one);
  23. }
  24. }
  25. }
  26. public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
  27. private IntWritable result = new IntWritable();
  28. @Override
  29. public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
  30. int sum = 0;
  31. for (IntWritable value : values) {
  32. sum += value.get();
  33. }
  34. result.set(sum);
  35. context.write(key, result);
  36. }
  37. }
  38. public static void main(String[] args) throws Exception {
  39. Configuration conf = new Configuration();
  40. conf.set("fs.defaultFS", "hdfs://localhost:9000");
  41. String[] otherArgs = new String[]{"input_1", "output_1"};
  42. if (otherArgs.length != 2) {
  43. System.err.println("Usage: Wordcount <in> <out>");
  44. System.exit(2);
  45. }
  46. Job job = Job.getInstance(conf, "Wordcount");
  47. job.setJarByClass(WordCount.class);
  48. job.setMapperClass(Map.class);
  49. job.setReducerClass(Reduce.class);
  50. job.setOutputKeyClass(Text.class);
  51. job.setOutputValueClass(IntWritable.class);
  52. FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  53. FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  54. System.exit(job.waitForCompletion(true) ? 0 : 1);
  55. }
  56. }

二,编写程序实现对输入文件的排序:

  1. 现在有多个输入文件,每个文件中的每行内容均为一个整数。要求读取所有文件中的整数,进行升序排序后,输出到一个新的文件中,输出的数据格式为每行两个整数,第一个数字为第二个整数的排序位次,第二个整数为原待排列的整数。下面是输入文件和输出文件的一个样例供参考。
  • 输入文件file1.txt的样例如下:
  1. 33
  2. 37
  3. 12
  4. 40
  • 输入文件file2.txt的样例如下:
  1. 4
  2. 16
  3. 39
  4. 5
  • 输入文件file3.txt的样例如下:
  1. 1
  2. 45
  3. 25
  • 根据输入文件file1.txt、file2.txt和file3.txt得到的输出文件如下:
  1. 1 1
  2. 2 4
  3. 3 5
  4. 4 12
  5. 5 16
  6. 6 25
  7. 7 33
  8. 8 37
  9. 9 39
  10. 10 40
  11. 11 45

实验过程:

  1. 创建文件file1.txt、file2.txt和file3.txt


    将上面样例内容复制进去
  2. 在HDFS建立input2文件夹


  3. 上传样例到HDFS中的input2文件夹


  4. 到eclipse上执行代码

实验代码:

  1. package cn.edu.zucc.mapreduce;
  2. import java.io.IOException;
  3. import org.apache.hadoop.conf.Configuration;
  4. import org.apache.hadoop.fs.Path;
  5. import org.apache.hadoop.io.IntWritable;
  6. import org.apache.hadoop.io.Text;
  7. import org.apache.hadoop.mapreduce.Job;
  8. import org.apache.hadoop.mapreduce.Mapper;
  9. import org.apache.hadoop.mapreduce.Reducer;
  10. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  11. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  12. public class ContentSort {
  13. public static class Map extends Mapper<Object, Text, IntWritable, IntWritable> {
  14. private static IntWritable data = new IntWritable();
  15. @Override
  16. public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
  17. String line = value.toString();
  18. data.set(Integer.parseInt(line));
  19. context.write(data, new IntWritable(1));
  20. }
  21. }
  22. public static class Reduce extends Reducer<IntWritable, IntWritable, IntWritable, IntWritable> {
  23. private static IntWritable linenum = new IntWritable(1);
  24. @Override
  25. public void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
  26. for (IntWritable val : values) {
  27. context.write(linenum, key);
  28. linenum = new IntWritable(linenum.get() + 1);
  29. }
  30. }
  31. }
  32. public static void main(String[] args) throws Exception {
  33. Configuration conf = new Configuration();
  34. conf.set("fs.defaultFS", "hdfs://localhost:9000");
  35. String[] otherArgs = new String[]{"input2", "output2"};
  36. if (otherArgs.length != 2) {
  37. System.err.println("Usage: ContentSort <in> <out>");
  38. System.exit(2);
  39. }
  40. Job job = Job.getInstance(conf, "ContentSort");
  41. job.setJarByClass(ContentSort.class);
  42. job.setMapperClass(Map.class);
  43. job.setReducerClass(Reduce.class);
  44. job.setOutputKeyClass(IntWritable.class);
  45. job.setOutputValueClass(IntWritable.class);
  46. FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  47. FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  48. System.exit(job.waitForCompletion(true) ? 0 : 1);
  49. }
  50. }
模仿上题完成以下内容:对于三个输入文件,即文件math、文件china和文件english,请编写MapReduce程序,对三个文件进行统计平均分,得到一个新的输出文件。下面是输入文件和输出文件的一个样例供参考。
  • 输入文件math.txt的样例如下:
  1. 张三 88
  2. 李四 99
  3. 王五 66
  4. 赵六 77
  • 输入文件algs.txt的样例如下:
  1. 张三 78
  2. 李四 89
  3. 王五 96
  4. 赵六 67
  • 输入文件english.txt的样例如下:
  1. 张三 80
  2. 李四 82
  3. 王五 84
  4. 赵六 86
  • 输出文件结果为:
  1. 张三 82
  2. 李四 90
  3. 王五 82
  4. 赵六 76

实验代码:

  1. package cn.edu.zucc.mapreduce;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import org.apache.hadoop.conf.Configuration;
  6. import org.apache.hadoop.fs.Path;
  7. import org.apache.hadoop.io.IntWritable;
  8. import org.apache.hadoop.io.LongWritable;
  9. import org.apache.hadoop.io.Text;
  10. import org.apache.hadoop.mapreduce.Job;
  11. import org.apache.hadoop.mapreduce.Mapper;
  12. import org.apache.hadoop.mapreduce.Reducer;
  13. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  14. import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
  15. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  16. import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
  17. public class AvgScore {
  18. public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
  19. @Override
  20. public void map(LongWritable key, Text value, Context context)
  21. throws IOException, InterruptedException {
  22. String line = value.toString();
  23. String[] nameAndScore = line.split(" ");
  24. List<String> list = new ArrayList<>(2);
  25. for (String nameOrScore : nameAndScore) {
  26. if (!"".equals(nameOrScore)) {
  27. list.add(nameOrScore);
  28. }
  29. }
  30. context.write(new Text(list.get(0)), new IntWritable(Integer.parseInt(list.get(1))));
  31. }
  32. }
  33. public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
  34. @Override
  35. public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
  36. int sum = 0;
  37. int count = 0;
  38. for (IntWritable value : values) {
  39. sum += Integer.parseInt(value.toString());
  40. count++;
  41. }
  42. int average = sum / count;
  43. context.write(key, new IntWritable(average));
  44. }
  45. }
  46. public static void main(String[] args) throws Exception {
  47. Configuration conf = new Configuration();
  48. conf.set("fs.defaultFS", "hdfs://localhost:9000");
  49. String[] otherArgs = new String[]{"input_2", "output_2"};
  50. if (otherArgs.length != 2) {
  51. System.err.println("Usage: AvgScore <in> <out>");
  52. System.exit(2);
  53. }
  54. Job job = Job.getInstance(conf, "AvgScore");
  55. job.setJarByClass(AvgScore.class);
  56. job.setMapperClass(Map.class);
  57. job.setReducerClass(Reduce.class);
  58. job.setOutputKeyClass(Text.class);
  59. job.setOutputValueClass(IntWritable.class);
  60. job.setInputFormatClass(TextInputFormat.class);
  61. job.setOutputFormatClass(TextOutputFormat.class);
  62. FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  63. FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  64. System.exit(job.waitForCompletion(true) ? 0 : 1);
  65. }
  66. }

三,对给定的表格进行信息挖掘:

  1. 下面给出一个child-parent的表格,要求挖掘其中的父子辈关系,给出祖孙辈关系的表格。
  • 输入文件table.txt内容如下:
  1. child parent
  2. Steven Lucy
  3. Steven Jack
  4. Jone Lucy
  5. Jone Jack
  6. Lucy Mary
  7. Lucy Frank
  8. Jack Alice
  9. Jack Jesse
  10. David Alice
  11. David Jesse
  12. Philip David
  13. Philip Alma
  14. Mark David
  15. Mark Alma
  • 输出文件内容如下:
  1. grandchild grandparent
  2. Mark Jesse
  3. Mark Alice
  4. Philip Jesse
  5. Philip Alice
  6. Jone Jesse
  7. Jone Alice
  8. Steven Jesse
  9. Steven Alice
  10. Steven Frank
  11. Steven Mary
  12. Jone Frank
  13. Jone Mary

实验过程:

  1. 创建文件table


    将上面样例内容复制进去
  2. 在HDFS建立input3文件夹


  3. 上传样例到HDFS中的input3文件夹


  4. 到eclipse上执行代码

实验代码:

  1. package cn.edu.zucc.mapreduce;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import org.apache.hadoop.conf.Configuration;
  6. import org.apache.hadoop.fs.Path;
  7. import org.apache.hadoop.io.Text;
  8. import org.apache.hadoop.mapreduce.Job;
  9. import org.apache.hadoop.mapreduce.Mapper;
  10. import org.apache.hadoop.mapreduce.Reducer;
  11. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  12. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  13. public class STJoin {
  14. public static int time = 0;
  15. public static class Map extends Mapper<Object, Text, Text, Text> {
  16. @Override
  17. public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
  18. String line = value.toString();
  19. String[] childAndParent = line.split(" ");
  20. List<String> list = new ArrayList<>(2);
  21. for (String childOrParent : childAndParent) {
  22. if (!"".equals(childOrParent)) {
  23. list.add(childOrParent);
  24. }
  25. }
  26. if (!"child".equals(list.get(0))) {
  27. String childName = list.get(0);
  28. String parentName = list.get(1);
  29. String relationType = "1";
  30. context.write(new Text(parentName), new Text(relationType + "+"
  31. + childName + "+" + parentName));
  32. relationType = "2";
  33. context.write(new Text(childName), new Text(relationType + "+"
  34. + childName + "+" + parentName));
  35. }
  36. }
  37. }
  38. public static class Reduce extends Reducer<Text, Text, Text, Text> {
  39. @Override
  40. public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
  41. if (time == 0) {
  42. context.write(new Text("grand_child"), new Text("grand_parent"));
  43. time++;
  44. }
  45. List<String> grandChild = new ArrayList<>();
  46. List<String> grandParent = new ArrayList<>();
  47. for (Text text : values) {
  48. String s = text.toString();
  49. String[] relation = s.split("\\+");
  50. String relationType = relation[0];
  51. String childName = relation[1];
  52. String parentName = relation[2];
  53. if ("1".equals(relationType)) {
  54. grandChild.add(childName);
  55. } else {
  56. grandParent.add(parentName);
  57. }
  58. }
  59. int grandParentNum = grandParent.size();
  60. int grandChildNum = grandChild.size();
  61. if (grandParentNum != 0 && grandChildNum != 0) {
  62. for (int m = 0; m < grandChildNum; m++) {
  63. for (int n = 0; n < grandParentNum; n++) {
  64. context.write(new Text(grandChild.get(m)), new Text(
  65. grandParent.get(n)));
  66. }
  67. }
  68. }
  69. }
  70. }
  71. public static void main(String[] args) throws Exception {
  72. Configuration conf = new Configuration();
  73. conf.set("fs.defaultFS", "hdfs://localhost:9000");
  74. String[] otherArgs = new String[]{"input3", "output3"};
  75. if (otherArgs.length != 2) {
  76. System.err.println("Usage: Single Table Join <in> <out>");
  77. System.exit(2);
  78. }
  79. Job job = Job.getInstance(conf, "Single table Join ");
  80. job.setJarByClass(STJoin.class);
  81. job.setMapperClass(Map.class);
  82. job.setReducerClass(Reduce.class);
  83. job.setOutputKeyClass(Text.class);
  84. job.setOutputValueClass(Text.class);
  85. FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  86. FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  87. System.exit(job.waitForCompletion(true) ? 0 : 1);
  88. }
  89. }
模仿上题完成以下内容:现有两个输入文件两个文件,一个是工厂名与地址编号的对应关系;另一个是地址编号和地址名的对应关系。要求从输入数据中找出工厂名和地址名的对应关系,输出"工厂名——地址名"表。
  • 输入文件factory.txt:
  1. factoryname addressID
  2. Beijing Red Star 1
  3. Shenzhen Thunder 3
  4. Guangzhou Honda 2
  5. Beijing Rising 1
  6. Guangzhou Development Bank 2
  7. Tencent 3
  8. Bank of Beijing 1
  • 输入文件address.txt:
  1. addressID addressname
  2. 1 Beijing
  3. 2 Guangzhou
  4. 3 Shenzhen
  5. 4 Xian
  • 输出文件内容如下:
  1. factoryname addressname
  2. Back of Beijing     Beijing
  3. Beijing Rising   Beijing
  4. Beijing Red Star     Beijing
  5. Guangzhou Development Bank   Guangzhou
  6. Guangzhou Honda       Guangzhou
  7. Tencent         Shenzhen
  8. Shenzhen Thunder       Shenzhen

实验代码:

  1. package cn.edu.zucc.mapreduce;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import org.apache.commons.lang.StringUtils;
  6. import org.apache.hadoop.conf.Configuration;
  7. import org.apache.hadoop.fs.Path;
  8. import org.apache.hadoop.io.Text;
  9. import org.apache.hadoop.mapreduce.Job;
  10. import org.apache.hadoop.mapreduce.Mapper;
  11. import org.apache.hadoop.mapreduce.Reducer;
  12. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  13. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  14. import org.apache.hadoop.util.GenericOptionsParser;
  15. public class MTJoin {
  16. public static int time = 0;
  17. public static class Map extends Mapper<Object, Text, Text, Text> {
  18. @Override
  19. protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
  20. String line = value.toString();
  21. if (line.contains("factoryname") || line.contains("addressID")) {
  22. return;
  23. }
  24. String[] strings = line.split(" ");
  25. List<String> list = new ArrayList<>();
  26. for (String information : strings) {
  27. if (!"".equals(information)) {
  28. list.add(information);
  29. }
  30. }
  31. String addressID;
  32. StringBuilder stringBuilder = new StringBuilder();
  33. if (StringUtils.isNumeric(list.get(0))) {
  34. addressID = list.get(0);
  35. for (int i = 1; i < list.size(); i++) {
  36. if (i != 1) {
  37. stringBuilder.append(" ");
  38. }
  39. stringBuilder.append(list.get(i));
  40. }
  41. context.write(new Text(addressID), new Text("1+" + stringBuilder.toString()));
  42. } else {
  43. addressID = list.get(list.size() - 1);
  44. for (int i = 0; i < list.size() - 1; i++) {
  45. if (i != 0) {
  46. stringBuilder.append(" ");
  47. }
  48. stringBuilder.append(list.get(i));
  49. }
  50. context.write(new Text(addressID), new Text("2+" + stringBuilder.toString()));
  51. }
  52. }
  53. }
  54. public static class Reduce extends Reducer<Text, Text, Text, Text> {
  55. @Override
  56. protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
  57. if (time == 0) {
  58. context.write(new Text("factoryname"), new Text("addressname"));
  59. time++;
  60. }
  61. List<String> factory = new ArrayList<>();
  62. List<String> address = new ArrayList<>();
  63. for (Text text : values) {
  64. String s = text.toString();
  65. String[] relation = s.split("\\+");
  66. if ("1".equals(relation[0])) {
  67. address.add(relation[1]);
  68. } else {
  69. factory.add(relation[1]);
  70. }
  71. }
  72. int factoryNum = factory.size();
  73. int addressNum = address.size();
  74. if (factoryNum != 0 && addressNum != 0) {
  75. for (int m = 0; m < factoryNum; m++) {
  76. for (int n = 0; n < addressNum; n++) {
  77. context.write(new Text(factory.get(m)),
  78. new Text(address.get(n)));
  79. }
  80. }
  81. }
  82. }
  83. }
  84. public static void main(String[] args) throws Exception {
  85. Configuration conf = new Configuration();
  86. conf.set("fs.defaultFS", "hdfs://localhost:9000");
  87. String[] ioArgs = new String[]{"input_3", "output_3"};
  88. String[] otherArgs = new GenericOptionsParser(conf, ioArgs)
  89. .getRemainingArgs();
  90. if (otherArgs.length != 2) {
  91. System.err.println("Usage: Multiple Table Join <in> <out>");
  92. System.exit(2);
  93. }
  94. Job job = Job.getInstance(conf, "Mutiple table join ");
  95. job.setJarByClass(MTJoin.class);
  96. job.setMapperClass(Map.class);
  97. job.setReducerClass(Reduce.class);
  98. job.setOutputKeyClass(Text.class);
  99. job.setOutputValueClass(Text.class);
  100. FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  101. FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  102. System.exit(job.waitForCompletion(true) ? 0 : 1);
  103. }
  104. }


作者:Tiny_16
链接:https://www.jianshu.com/p/7328bb45a7cd
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/337669
推荐阅读