亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用mapreduce的第二大薪水-輸出與預期不符

使用mapreduce的第二大薪水-輸出與預期不符

鳳凰求蠱 2021-04-09 14:15:33
我寫了一個小的mapreduce作業來查找數據集中第二高的薪水。我相信第二個最高薪水邏輯是正確的。但是我得到了多個不正確的輸出,應該只有一個名稱為John的輸出,例如9000。而且輸出也不正確,這里我給出了數據集和代碼hh,0,Jeet,3000hk,1,Mayukh,4000nn,2,Antara,3500mm,3,Shubu,6000ii,4,Parsi,8000  輸出應該是Shubu,6000,但是我得到以下輸出  Antara    -2147483648  Mayukh    -2147483648  Parsi      3500  Shubu      4000我正在使用的代碼是 public class SecondHigestMapper extends Mapper<LongWritable,Text,Text,Text>{private Text salary = new Text();private Text name = new Text();public void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException{    if(key.get()!=0){        String split[]= value.toString().split(",");        salary.set(split[2]+";"+split[3]);        name.set("ignore");        context.write(name,salary);    }}} public class SecondHigestReducer extends Reducer<Text,Text,Text,IntWritable>{public void reduce(Text key,Iterable<Text> values,Context context) throws IOException, InterruptedException{    int highest = 0;    int second_highest = 0;    int salary;    for(Text val:values){        String[] fn = val.toString().split("\\;");        salary = Integer.parseInt(fn[3]);        if(highest < salary){              second_highest = highest;              highest =salary;         } else if(second_highest < salary){              second_highest = salary;        }    }    String seconHigest = String.valueOf(second_highest);    context.write(new Text(key),new Text(seconHigest));} }
查看完整描述

1 回答

?
MYYA

TA貢獻1868條經驗 獲得超4個贊

使用單個鍵將所有薪水強制到一個減速器中


name.set("ignore");  // Could use a NullWritable 

salary.set(split[2]+";"+split[3])); // change to TextWritable 

context.write(name,salary);  // need to change the signature of the mapper class 

然后在化簡器中,將方法更改為接受文本值,然后將其拆分,轉換薪水,然后進行比較


查看完整回答
反對 回復 2021-04-21
  • 1 回答
  • 0 關注
  • 215 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號