簡體   English   中英

當我指定IntWritable時,為什么我的map reduce程序在文本中給我輸出

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

我的測試集是:

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

我的映射器類:

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);
    }
}

減速器類:

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));
    }
}

驅動類別:

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);

}

我被放為:

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

而我正在嘗試查找每個公司出售的單位。

我相信輸出是由身份(默認值)reduce(僅輸出帶有制表符的映射器鍵和值)而不是您的生成。 不知道為什么會這樣,但是我懷疑BasicConfigurator.configure();

在ResourceManager UI中,您可以驗證mapred.reducer.class,轉到作業,然后在左側菜單上查看所使用的實際作業屬性。

我錯誤地擴展了原本應該是Reducer的Reducer,Text,IntWritable>

由於我沒有將@Override注釋用於reduce方法,因此這並非針對編譯時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM