多输入路径

来源:互联网 发布:足球球员数据库 编辑:程序博客网 时间:2024/06/13 13:37
目前为止知道MapReduce有三种路径输入方式。
1、第一种是通过一下方式输入:
  1. FileInputFormat.addInputPath(job, new Path(args[0]));
  2. FileInputFormat.addInputPath(job, new Path(args[1]));
  3. FileInputFormat.addInputPath(job, new Path(args[2]));
  4. FileInputFormat.addInputPath(job, new Path(args[3]));
复制代码
这种方式可以接收多个路径下的文件输入,但是这些文件都是通过一个Map进行处理
2、第二种是通过以下方式输入(第二个路径参数是通过,分割的多个路径):
  1. FileInputFormat.addInputPaths(job, args[0] + "," + args[1] + "," + args[2]);
复制代码
这种方式跟第一种相似,看源码会发现,该方式是先将路径通过,分割成String[] paths数组形式,然后再循环调用第一种方式,而且他也是通过一个Map进行处理
3、第三种是通过以下方式输入:
  1. MultipleInputs.addInputPath(job, new Path(args[0]), TextInputFormat.class,EmpMapper.class);
  2. MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class,EmpMapper.class);
  3. MultipleInputs.addInputPath(job, new Path(args[2]), TextInputFormat.class,TestMapper.class);
复制代码
这种方式是针对不同的输入文件,他们的格式可能不同,然后针对他们的格式编写相应的Map分别进行处理,这种方式更灵活些。
目前只用到了上述三种方式,欢迎大家补充。
0 0
原创粉丝点击