2013-08-25 32 views
0

今天我正在使用分區程序。它是hadoop定製分區程序中的基本程序。以下是我的分區代碼片段。hadoop分區程序越來越不正確減少計數

公共類VowelConsPartitioner擴展分區程序{

@Override 
public int getPartition(Text letterType, IntWritable count, int redCnt) { 
    // TODO Auto-generated method stub 

    //System.out.println("reduce cnt in partitioner: "+redCnt); 
    if(letterType.toString().equalsIgnoreCase("vowel")){ 

     //System.out.println("vowel sound: "+1%redCnt); 
     return letterType.toString().hasCode()%redCnt; 
    } 

    if(letterType.toString().equalsIgnoreCase("consonent")){ 
     //System.out.println("Cons sound: "+2%redCnt); 
     return letterType.toString().hasCode()%redCnt; 
    } 

    else 
     return 0; 
} 

}

我把我減速在我的司機這樣的類....

job.setNumReduceTasks(3); job.setPartitionerClass(VowelConsPartitioner.class);

我想保留1個以上的減速器。但是我只能在一個reducer中獲得o/p。此外,如果您看到分區代碼,則第一個sysout(我已經評論過)將redCnt設爲1.我不確定在我的驅動程序類中將其計數設置爲3時發生了什麼。有人可以幫我解決這個問題嗎?

僅供參考...我正在製作罐子&在HDFS上運行。

+0

所有,它的hashCode()。不是hasCode()我的不好!它的錯字 –

回答

0

你的邏輯似乎是正確的!我想你需要創建一個jar文件並在終端中運行以獲得分區結果。

乾杯!

+0

邏輯分區器https://gist.github.com/krishnakalyan3/6349973驅動程序https://gist.github.com/krishnakalyan3/6349965減速器https://gist.github.com/krishnakalyan3/6349961映射器https: //gist.github.com/krishnakalyan3/6349950 –