hbase mapreduce:在reducer中写入hbase

mzaanser  于 2021-06-03  发布在  Hadoop
关注(0)|答案(2)|浏览(459)

我正在学习hbase。我知道如何使用hadoopmapreduce编写java程序,并将输出写入hdfs;但现在我想将相同的输出写入hbase,而不是hdfs。它应该有一些类似的代码,就像我以前在hdfs中做的那样:

context.write(key,value);

有人能给我举个例子来实现这一点吗?

vqlkdk9b

vqlkdk9b1#

在设置作业时,应该能够使用tableoutputformat,而不是使用fileoutputformat。
http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/mapreduce/tableoutputformat.html
你还得修改一下你的减速机。
引用上一页:
转换map/reduce输出并将其写入hbase表。当输出值必须是put或delete示例时,将忽略该键。

e0bqpujr

e0bqpujr2#

有一种方法:

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;
   }
}

您可以在这里阅读有关表Map器的内容

相关问题