2013-08-25 33 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 –