简体   繁体   English

在HADOOP映射中使用泛型可减少问题

[英]use of Generics in HADOOP map reduce problems

My question seems to be silly to the HADOOP users. 我的问题对于HADOOP用户而言似乎很愚蠢。 But I am little confused with use of Generics in map reduce problem like "WORD COUNT". 但是我对在映射减少问题中使用泛型感到困惑,例如“ WORD COUNT”。

I know that Generics are used bascialy for Type Casting and Type Safety. 我知道,泛型被基本用于类型转换和类型安全。 But I can not link up the concept here. 但是我不能在这里将这个概念联系起来。

In word count problem, 在字数问题上,

public class WordCountMapper extends
        Mapper<LongWritable, Text, Text, LongWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        // TODO Auto-generated method stub
        ...

        }
    }

}

Please can anyone clear me the use of Generics here . 请任何人在这里让我明白泛型的使用 Please correct me if I've done any mistake while asking this question. 如果我在问这个问题时犯了任何错误,请纠正我。

I now understand the generics are used here for key value pair (KEY IN, VALUE IN, KEY OUT, VALUE OUT). 现在,我了解将泛型用于键值对(KEY IN,VALUE IN,KEY OUT,VALUE OUT)。 But still I am not clear, why Generics is used here for key value pair. 但是我仍然不清楚,为什么在这里将泛型用于键值对。 Is not there other way to do the same. 没有其他方法可以做同样的事情。 What is the benefit of using Generics here? 在这里使用泛型有什么好处?

Thanks! 谢谢!

MapReduce uses Generics specifically in Mapper and Reducer to specify what kind of input and output is expected to read in and write out. MapReduce在Mapper和Reducer中专门使用泛型来指定期望读入和写出哪种输入和输出。

In the example you have specified your WordCountMapper extends Mapper class with specified generics Mapper<LongWritable, Text, Text, LongWritable> where the first two classes LongWritable and Text represents the input key and value the Mapper class is expecting to read, while the last two classes Text and LongWritable represents the output key and value classes the map method is expected to emit out. 在该示例中,您指定了WordCountMapper以指定的泛型Mapper<LongWritable, Text, Text, LongWritable>扩展了Mapper类,其中前两个类LongWritableText表示Mapper类期望读取的输入键和值 ,而后两个TextLongWritable类表示map方法应发出的输出键和值类。

This thread discussion gives more insight into why generics have been implemented in MapReduce. 通过该线程讨论,可以更深入地了解为什么在MapReduce中实现了泛型。 Also, this JIRA Issue gives more information. 另外,此JIRA问题提供了更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM