我正在学习 HBase。我知道如何使用 Hadoop MapReduce 编写 Java 程序并将输出写入 HDFS;但现在我想将相同的输出写入 HBase,而不是 HDFS。它应该有一些类似的代码,就像我之前在 HDFS 中所做的那样:
context.write(key,value);
谁能给我一个例子来实现这个?
最佳答案
这是一种方法:
public static class MyMapper extends TableMapper<ImmutableBytesWritable, Put> {
public void map(ImmutableBytesWritable row, Result value, Context context) throws IOException, InterruptedException {
// this example is just copying the data from the source table...
context.write(row, resultToPut(row,value));
}
private static Put resultToPut(ImmutableBytesWritable key, Result result) throws IOException {
Put put = new Put(key.get());
for (KeyValue kv : result.raw()) {
put.add(kv);
}
return put;
}
}
您可以在这里阅读关于 Table Mapper 的信息
关于java - HBase 映射减少 : write into HBase in Reducer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18603031/