【问题标题】:Set TTL for a column family in HBase using shell and using Java API使用 shell 和 Java API 为 HBase 中的列族设置 TTL
【发布时间】:2015-03-29 16:17:46
【问题描述】:

我是 HBase 的新手,我已经在最后进行了搜索,但我无法找到一种简单直接的方法来在 HBase 的列族中设置 TTL 属性。请指定使用 shell 和使用 Java API 的两种方式。

【问题讨论】:

    标签: java apache hbase


    【解决方案1】:

    使用 Java API:

    HColumnDescriptor cfDescriptor = new HColumnDescriptor(Bytes.toBytes("cfName"));
    cfDescriptor.setTimeToLive(20); // in seconds
    
    tableDesc.addFamily(cfDescriptor);
    admin.createTable(tableDesc);
    

    并使用外壳:

    alter ‘tableName′, NAME => ‘cfname′, TTL => 20
    

    【讨论】:

    • 感谢您的回复。
    【解决方案2】:

    使用 Java API 修改现有表以添加 TTL:

    HConnection connection = HBaseConnection.createConnection("localhost", "2181");
                HBaseAdmin hBaseAdmin = new HBaseAdmin(connection);
                HTableDescriptor hTableDescriptor = new HTableDescriptor("TTLDemo".getBytes());
                HColumnDescriptor hColumnDescriptor = new HColumnDescriptor("C".getBytes());
                hColumnDescriptor.setTimeToLive(2);
                hTableDescriptor.addFamily(hColumnDescriptor);
                hBaseAdmin.modifyTable("TTLDemo", hTableDescriptor);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多