HBase 建表API使用

 


String table = "table";
Configuration conf = HBaseConfiguration.create();
Connection conn = ConnectionFactory.createConnection(conf);
Admin admin = conn.getAdmin();
//删除指定的表要先disable,然后在删除
admin.disableTable(TableName.valueOf(table));
admin.deleteTable(TableName.valueOf(table));


//创建表,设置指定的属性值
//org.apache.hadoop.hbase.regionserver.DateTieredStoreEngine StoreEngine是在2.0以后的版本才有的
//设置列族的属性
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder("cf".getBytes())
        .setCompressTags(true)
        .setInMemoryCompaction(MemoryCompactionPolicy.ADAPTIVE)
        .setMinVersions(2)
        .setTimeToLive(60 * 60 * 24 * 7)
        .setValue("COMPRESSION","SNAPPY")
        .setValue("hbase.hstore.engine.class","org.apache.hadoop.hbase.regionserver.DateTieredStoreEngine")
        .setValue("hbase.hstore.blockingStoreFiles","60")
        .setValue("hbase.hstore.compaction.min","2")
        .setValue("hbase.hstore.compaction.max","60")
        .setCompactionCompressionType(Compression.Algorithm.SNAPPY)
        .build();

//设置表的属性
TableDescriptor td = TableDescriptorBuilder.newBuilder(TableName.valueOf(table))
        .setMemStoreFlushSize(256 * 1024 * 1024)
        .setColumnFamily(columnFamilyDescriptor)
        .setCompactionEnabled(true)
        .setMaxFileSize(1024 * 1024 * 1024)
        .setValue("COMPRESSION","SNAPPY")
        .setValue("hbase.hstore.engine.class","org.apache.hadoop.hbase.regionserver.DateTieredStoreEngine")
        .setValue("hbase.hstore.blockingStoreFiles","60")
        .setValue("hbase.hstore.compaction.min","2")
        .setValue("hbase.hstore.compaction.max","60")
        .setValue("BLOCKSIZE","65536").build();

//设置预分区的值,rowkey安装字典序列排序,目前是按照开头数字是1-9分成10个分区
byte[][] splitKeys = {
        Bytes.toBytes("1"),
        Bytes.toBytes("2"),
        Bytes.toBytes("3"),
        Bytes.toBytes("4"),
        Bytes.toBytes("5"),
        Bytes.toBytes("6"),
        Bytes.toBytes("7"),
        Bytes.toBytes("8"),
        Bytes.toBytes("9")
};

//创建表
admin.createTable(td,splitKeys);

最后在WebUI上查看表的描述状态如下:

'test_db_zero9', {TABLE_ATTRIBUTES => {MAX_FILESIZE => '1073741824', MEMSTORE_FLUSHSIZE => '268435456', METADATA => {'BLOCKSIZE' => '65536', 'COMPACTION_ENABLED' => 'true', 'COMPRESSION' => 'SNAPPY', 'hbase.hstore.blockingStoreFiles' => '60', 'hbase.hstore.compaction.max' => '60', 'hbase.hstore.compaction.min' => '2', 'hbase.hstore.engine.class' => 'org.apache.hadoop.hbase.regionserver.DateTieredStoreEngine'}}, {NAME => 'cf', MIN_VERSIONS => '2', TTL => '604800 SECONDS (7 DAYS)', COMPRESSION => 'SNAPPY', METADATA => {'hbase.hstore.engine.class' => 'org.apache.hadoop.hbase.regionserver.DateTieredStoreEngine', 'COMPRESS_TAGS' => 'true', 'hbase.hstore.blockingStoreFiles' => '60', 'COMPRESSION_COMPACT' => 'SNAPPY', 'hbase.hstore.compaction.min' => '2', 'IN_MEMORY_COMPACTION' => 'ADAPTIVE', 'hbase.hstore.compaction.max' => '60'}}

Region的信息如下:

在三台机器上的分布如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值