簡體   English   中英

是否可以使用Java截斷並啟用HBase表?

[英]Is it possible to truncate and enable a HBase table using Java?

有沒有辦法使用Java API截斷並重新啟用htable,類似於在shell中使用以下命令?

truncate 'tablename'
enable 'tablename'

有沒有比迭代每行和使用deleteAll更好的方法?

如果你可以使用Thrift和Python和HappyBase:

import happybase

c = happybase.Connection()
c.disable_table('tablename')
c.delete_table('tablename')
c.create_table(
    'tablename', {'cf1': dict() }
)

這創造了一個新的空桌子。

現在可以使用admin

Admin admin = Connection.getAdmin();
admin.truncateTable(TableName.valueOf("name_of_the_table",true);

我正在使用版本0.98,它不包含該API,因此這里是一個示例代碼:

public static void main(String[] args) throws Exception{
    String table = "yourTableName";
    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "hbaseZK host");
    HBaseAdmin hBaseAdmin = new HBaseAdmin(conf);
    HTableDescriptor desciptor = hBaseAdmin.getTableDescriptor(table.getBytes());
    hBaseAdmin.disableTable(table);
    hBaseAdmin.deleteTable(table);
    hBaseAdmin.createTable(desciptor);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM