我有一张包含大约十亿条记录的表格。我想改变这些记录的密钥,即以某种方式获取记录更改其密钥,删除所获取的内容保存新记录!让我们说例如我的密钥是[time-accountId],我想将其更改为[account-time] 我想用不同的密钥获取实体创建新,用[time-account]删除实体并用[accout-time]
保存新实体完成此任务的最佳方法是什么?
我正在考虑M / R,但如何删除M / R实体?
答案 0 :(得分:2)
你需要一个mapreduce,它会为你的每一行产生一个Put和一个Delete。此处只需要一个映射器,因为您不需要对数据进行聚合,因此请跳过reducer:
TableMapReduceUtil.initTableReducerJob(
table, // output table
null, // reducer class
job);
您的映射器必须同时生成Put和Delete,因此要使用的输出值类是Mutation(https://hbase.apache.org/0.94/apidocs/org/apache/hadoop/hbase/client/Mutation.html):
TableMapReduceUtil.initTableMapperJob(
table, // input table
scan, // Scan instance to control CF and attribute selection
MyMapper.class, // mapper class
ImmutableBytesWritable.class, // mapper output key
Mutation.class, // mapper output value
job);
然后你的映射器将如下所示:
Delete delete = ...
context.write(oldKey, delete);
Put put = ...
context.write(newKey, put);