2011-12-08 57 views
1

我的目的是將數據從Hbase Tables遷移到Flat(比如csv格式)文件。 我使用 TableMapReduceUtil.initTableMapperJob(tableName,scan, GetCustomerAccountsMapper.class,Text.class,Result.class, job); 用於掃描HBase表和MapMapper for Mapper。 我的challange處於強制Reducer將Row值(以平面格式標準化)轉儲到本地(或Hdfs)文件系統時。 我的問題是我既沒有看到Reducer的日誌,也沒有看到我在Reducer中提到的路徑上的任何文件。將數據從HBase遷移到文件系統。 (寫Reducer輸出到本地或Hadoop文件系統)

這是我的第二或第三先生的工作和第一個嚴重的工作。經過兩天的努力,我仍然無能爲力,無法實現自己的目標。

如果有人能夠展示正確的方向,那將會很棒。

這裏是我的減速代碼 -

public void reduce(Text key, Iterable<Result> rows, Context context) 
      throws IOException, InterruptedException { 
FileSystem fs = LocalFileSystem.getLocal(new Configuration()); 
    Path dir = new Path("/data/HBaseDataMigration/" + tableName+"_Reducer" + "/" +  key.toString()); 

FSDataOutputStream fsOut = fs.create(dir,true); 

for (Result row : rows) { 
try { 
String normRow = NormalizeHBaserow(
Bytes.toString(key.getBytes()), row, tableName); 
fsOut.writeBytes(normRow); 

//context.write(new Text(key.toString()), new Text(normRow)); 
    } catch (BadHTableResultException ex) { 
    throw new IOException(ex); 
} 
} 
fsOut.flush();   
fsOut.close(); 

我對減速機的輸出配置提前

Path out = new Path(args[0] + "/" + tableName+"Global"); 
FileOutputFormat.setOutputPath(job, out); 

謝謝 - Panks

回答

0

爲什麼不減少到HDFS,一旦完成使用HDFS FS到導出文件

hadoop fs -get /user/hadoop/file localfile 

如果您確實想要在縮減階段處理它,請參閱InfoQ上的this article on OutputFormat

相關問題