【问题标题】:Update and Delete Map/Reduce in HBase在 HBase 中更新和删除 Map/Reduce
【发布时间】:2014-03-16 09:12:54
【问题描述】:

我有一个包含大约十亿条记录的表。我想更改这些记录的键,即获取记录以某种方式更改其键,删除获取的内容保存新记录!例如,假设我的密钥是 [time-accountId],我想将其更改为 [account-time] 我想用不同的键获取实体创建新的,用 [time-account] 删除实体并用 [accout-time] 保存新实体

完成这项任务的最佳方法是什么?

我正在考虑 M/R 但如何删除带有 M/R 的实体?

【问题讨论】:

    标签: mapreduce hbase


    【解决方案1】:

    您需要一个 mapreduce,它将为表的每一行生成一个 Put 和一个 Delete。这里只需要一个映射器,因为您不需要对数据进行聚合,因此请跳过减速器:

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

    【讨论】:

    • 我会试试这个,它有效然后你的答案就是接受的答案:P
    猜你喜欢
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    相关资源
    最近更新 更多