简体   繁体   English

当我指定IntWritable时,为什么我的map reduce程序在文本中给我输出

[英]Why my map reduce program is giving me output in Text when i have specified IntWritable

My test set is : 我的测试集是:

Onida|Lucid|18|Uttar Pradesh|232401|16200
Akai|Decent|16|Kerala|922401|12200
Lava|Attention|20|Assam|454601|24200
Zen|Super|14|Maharashtra|619082|9200
Samsung|Optima|14|Madhya Pradesh|132401|14200

My mapper class: 我的映射器类:

public class UnitsSoldPerCompanyMapper extends Mapper<LongWritable,Text,Text,Text>{

    public void map(LongWritable inputKey, Text inputValue,Context context) throws IOException, InterruptedException{
        String[] lineArray= inputValue.toString().split("\\|");
        Text companyName = new Text(lineArray[0]);
        Text productName = new Text(lineArray[1]);
        context.write(companyName,productName);
    }
}

Reducer class: 减速器类:

public class UnitsSoldPerCompanyReducer extends Reducer<Text,Iterable<Text>,Text,IntWritable>{

    public void reduce(Text companyKey,Iterable<Text> productName,Context context) throws IOException, InterruptedException{

        IntWritable counter1= new IntWritable();
        int counter =0;

        for(Text values : productName ){
            System.out.println(values);
            counter++;
        }
        counter1.set(counter);
        //IntWritable sum= new IntWritable(counter);
        context.write(companyKey, new IntWritable(1));
    }
}

Driver class: 驱动类别:

public class UnitsSoldPerCompanyDriver {

public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

    Configuration conf = new Configuration();// To set job related
                                                // configuration

    // @SuppressWarnings("deprecation")
    @SuppressWarnings("deprecation")
    Job job = new Job(conf, "TaskofJob");
    job.setJarByClass(UnitsSoldPerCompanyDriver.class);

    // Job job = new Job(conf,"TvSalesAcrossLocations");

    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

    job.setMapperClass(UnitsSoldPerCompanyMapper.class);
    job.setReducerClass(UnitsSoldPerCompanyReducer.class);

    BasicConfigurator.configure();
    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(Text.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);

    // job.setInputFormatClass(TextInputFormat.class);
    // job.setOutputFormatClass(TextOutputFormat.class);

    job.waitForCompletion(true);

}

I am getting out put as: 我被放为:

Akai    Decent
Lava    Attention
Lava    Attention
Lava    Attention
NA  Lucid
Onida   NA
Onida   Decent
Onida   Lucid
Onida   Lucid
Samsung Super
Samsung Super
Samsung Super
Samsung Decent
Samsung Optima
Samsung Optima
Samsung Optima

Whereas, I am trying to find the units sold per company. 而我正在尝试查找每个公司出售的单位。

I believe that output is generated by the identity (default) reducer (which just outputs the mapper keys and values with tabs), instead of yours. 我相信输出是由身份(默认值)reduce(仅输出带有制表符的映射器键和值)而不是您的生成。 Not sure why is that but I suspect BasicConfigurator.configure(); 不知道为什么会这样,但是我怀疑BasicConfigurator.configure();

In the ResourceManager UI, you can verify mapred.reducer.class, go to the job and on the left menu you can see the actual job properties that where used. 在ResourceManager UI中,您可以验证mapred.reducer.class,转到作业,然后在左侧菜单上查看所使用的实际作业属性。

I had by mistakely extended Reducer,Text,IntWritable>, which was supposed to be Reducer 我错误地扩展了原本应该是Reducer的Reducer,Text,IntWritable>

This was not pointed at compile time since i had not used @Override annotation for reduce method. 由于我没有将@Override注释用于reduce方法,因此这并非针对编译时。

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

相关问题 为什么我的程序在运行时给我错误的输出? - Why is my program giving me the wrong output when I run it? MapReduce 职位:我怎么收<text, intwritable>在 Map 阶段和 output<text, text> 在减少阶段?</text,></text,> - MapReduce Job: How do I take in <Text, IntWritable> during Map phase and output <Text, Text> in Reduce phase? 访问同步方法时,为什么我的线程给我这个输出? - Why are my threads giving me this output when accessing a synchronized method? 使用IntWritable的Hadoop Reduce输出始终在2处停止 - Hadoop Reduce output using IntWritable always stops at 2 为什么我的程序没有给出预期的输出? - Why is my program not giving the expected output? 为什么这会给我这个 output? - Why is this giving me this output? 为什么HTTP响应未提供我指定的数据范围? - Why is the HTTP response not giving me my specified range of data? 为什么我的程序为什么一直给我一个ArrayIndexOutOfBoundsException,即使我没有一个也很难 - Why does my program keeps giving me an ArrayIndexOutOfBoundsException even tough I haven't got one 我的程序给我一个StackOverflowError - My program is giving me a StackOverflowError 为什么我的Java Morse代码翻译器给我错误的输出? - Why is my Java Morse Code translator giving me the wrong output?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM