2017-02-12 38 views
0

我有一個需求,我只需要從HBase的值而不是行鍵寫入輸出文件。 爲此我使用了NullWritable.class作爲我的地圖輸出鍵類型。 現在我必須根據列值對輸出數據進行分區。但正如我們所知,自定義分區基於密鑰工作,爲此我得到了異常。Mapreduce Hadoop中的NullWritable鍵類型的自定義分區

Caused by: java.io.IOException: Illegal partition for (null) (40) 

這是正是我在MapTask.class

越來越例外
if (partition < 0 || partition >= partitions) { 
      throw new IOException("Illegal partition for " + key + " (" + 
       partition + ")"); 
     } 

在這裏,我的分區值是如何1,這是越來越跟我回INT分區40相比,然後拋出異常

這是我使用的驅動程序代碼。

TableMapReduceUtil.initTableMapperJob(args[0], // input table 
       scan, // Scan instance to control CF and attribute selection 
       DefaultMapper.class, // mapper class 
       NullWritable.class, // mapper output value 
       Text.class, // mapper output key 
       job); 

這是我的分區代碼

public class FinancialLineItemPartioner extends Partitioner< NullWritable,Text> { 
    public int getPartition(NullWritable key, Text value, int setNumRedTask) { 
     String str = key.toString(); 
     if (str.contains("Japan|^|BUS")) { 
      return 0; 
     } else if (str.contains("Japan|^|CAS")) { 
      return 1; 
     } else if (str.contains("Japan|^|CUS")) { 
      return 2; 
     }else { 
      return 3; 
     } 

請建議..

注意:如果我互換圖輸出鍵/值參數,然後我減速機不能正常工作。

+0

在映射器中使用null鍵沒有意義。你想如何在reducer中對你的值進行分組? – AdamSkywalker

回答

0

問題出在VM上。同步代碼在羣集環境中工作正常。