Hadoop,MapReduce - 多个输入/输出路径

Sha*_*h.1 5 java hadoop mapreduce

在为我的MapReduce作业制作Jar的输入文件中,我使用的是Hadoop-local命令.我想知道是否有一种方法,而不是专门为我在MapReduce作业中使用的输入文件夹中的每个文件指定路径,是否可以指定并传递输入文件夹中的所有文件.这是因为我试图配置的MapReduce作业的性质,文件的内容和数量可能会改变,因为我不知道具体的文件数量,除了这些文件的内容,是否有办法将所有文件从输入文件夹传递到我的MapReduce程序,然后遍历每个文件以计算某个函数,然后将结果发送到Reducer.我只使用一个Map/Reduce程序,而且我用Java编写代码.我可以使用hadoop-moonshot命令,但我现在正在使用hadoop-local.

谢谢.

Rav*_*abu 1

您不必传递单个文件作为MapReduce作业的输入。

FileInputFormat类已经提供了 API 来接受多个文件列表作为 MapReduce 程序的输入。

public static void setInputPaths(Job job,
                 Path... inputPaths)
                          throws IOException
Run Code Online (Sandbox Code Playgroud)

将路径添加到映射缩减作业的输入列表中。参数:

conf - 作业的配置

path - 要添加到 Map-Reduce 作业的输入列表中的路径。

Apache教程中的示例代码

Job job = Job.getInstance(conf, "word count");
FileInputFormat.addInputPath(job, new Path(args[0]));
Run Code Online (Sandbox Code Playgroud)

MultipleInputs提供以下 API。

public static void addInputPath(Job job,
                Path path,
                Class<? extends InputFormat> inputFormatClass,
                Class<? extends Mapper> mapperClass)
Run Code Online (Sandbox Code Playgroud)

将具有自定义输入格式和映射器的路径添加到映射缩减作业的输入列表中。

相关SE问题:

hadoop可以从多个目录和文件获取输入

有关多个输出路径上的第二个查询,请参阅MultipleOutputs API。

FileOutputFormat.setOutputPath(job, outDir);

// Defines additional single text based output 'text' for the job
MultipleOutputs.addNamedOutput(job, "text", TextOutputFormat.class,
LongWritable.class, Text.class);

// Defines additional sequence-file based output 'sequence' for the job
MultipleOutputs.addNamedOutput(job, "seq",
SequenceFileOutputFormat.class,
LongWritable.class, Text.class);
Run Code Online (Sandbox Code Playgroud)

查看有关多个输出文件的相关 SE 问题。

在hadoop中写入多个文件夹?

hadoop方法将输出发送到多个目录