将数据从HBase迁移到FileSystem。 (将Reducer输出写入Local或Hadoop文件系统)

时间:2011-12-08 10:53:59

标签: hadoop mapreduce hbase

我的目的是将数据从Hbase表迁移到Flat(比如csv格式化)文件。 我习惯了     TableMapReduceUtil.initTableMapperJob(tableName,scan,                 GetCustomerAccountsMapper.class,Text.class,Result.class,                     工作); 用于扫描HBase表和TableMapper用于Mapper。 我的挑战在于强制Reducer将Row值(以flattened格式标准化)转储到本地(或Hdfs)文件系统。 我的问题是我既没有看到Reducer的日志,也没有看到我在Reducer中提到的路径中的任何文件。

这是我的第二或第三个MR工作,也是第一个严肃的工作。经过两天的努力,我仍然无法实现我的目标。

如果有人能够表明正确的方向,那就太好了。

这是我的减速机代码 -

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

1 个答案:

答案 0 :(得分:0)

为什么不缩小为HDFS并且一旦完成使用hdfs fs导出文件

hadoop fs -get /user/hadoop/file localfile

如果您确实想在reduce阶段处理它,请查看InfoQ上的this article on OutputFormat

相关问题