繁体   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