如果2个映射器输出相同的关键帧,那么对减少器的输入将是什么



在学习Map reduce时,我有以下疑问。如果有人能回答,那将是非常有帮助的。

我有两个映射器在同一个文件上工作-我使用MultipleInputFormat 配置了它们

mapper 1-预期输出[在提取文件的几列之后]

a - 1234
b - 3456
c - 1345

映射器2预期输出[提取同一文件的几列后]

a - Monday
b - Tuesday
c - Wednesday

还有一个reducer函数,它只输出作为输入的键和值对所以我希望输出是我所知道的,类似的键将被打乱以形成一个列表。

a - [1234,Monday]
b - [3456, Tuesday]
c - [1345, Wednesday]

但我得到了一些奇怪的输出。我想只有1个Mapper正在运行。这难道不是意料之中的事吗?每个映射器的输出会被单独打乱吗?两个映射程序会并行运行吗?

对不起,如果这是一个蹩脚的问题请理解我是Hadoop和Map Reduce 的新手

以下是代码

//Mapper1
public class numbermapper extends Mapper<Object, Text, Text, Text>{
    public void map(Object key,Text value, Context context) throws IOException, InterruptedException {
        String record = value.toString();
        String[] parts = record.split(",");
        System.out.println("***Mapper number output "+parts[0]+"  "+parts[1]);
        context.write(new Text(parts[0]), new Text(parts[1]));
    }
}
//Mapper2
public class weekmapper extends Mapper<Object, Text, Text, Text> {
    public void map(Object key, Text value, Context context)
            throws IOException, InterruptedException {
        String record = value.toString();
        String[] parts = record.split(",");
        System.out.println("***Mapper week output "+parts[0]+"   "+parts[2]);
        context.write(new Text(parts[0]), new Text(parts[2]));
    }
}
//Reducer
public class rjoinreducer extends Reducer<Text, Text, Text, Text> {
public void reduce(Text key, Text values, Context context)
    throws IOException, InterruptedException {
   context.write(key, values);
}
}
//Driver class
public class driver {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        Job job = new Job(conf, "Reduce-side join");
        job.setJarByClass(numbermapper.class);
        job.setReducerClass(rjoinreducer.class);
        job.setMapOutputValueClass(Text.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        MultipleInputs.addInputPath(job, new Path(args[0]),TextInputFormat.class, numbermapper.class);
        MultipleInputs.addInputPath(job, new Path(args[0]),TextInputFormat.class, weekmapper.class);
        Path outputPath = new Path(args[1]);

        FileOutputFormat.setOutputPath(job, outputPath);
        outputPath.getFileSystem(conf).delete(outputPath);
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}

这是我得到的O/p-

a     Monday
b     Tuesday
c     Wednesday

使用的数据集

a,1234,Monday
b,3456,Tuesday
c,1345,Wednesday

多输入格式只需要获取一个文件并在其上运行一个映射器,因为我为两个映射器提供了相同的路径。

当我将数据集复制到另一个文件,并运行相同的程序,获取两个不同的文件(内容相同,但文件名称不同)时,我得到了预期的输出。

所以我现在明白了,来自不同映射器函数的输出也是基于键组合的,而不仅仅是来自同一映射器功能的输出。

谢谢你的帮助。。。。!!!

最新更新