码迷,mamicode.com
首页 > 其他好文 > 详细

HBase预分区のUniformSplit

时间:2014-11-05 13:05:28      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   java   for   

如果某个hbase的表查询只是以随机查询为主,可以用UniformSplit的方式进行,它是按照原始byte值(从0x00~0xFF)右边以00填充。以这种方式分区的表在插入的时候需要对rowkey进行一个技巧性的改造, 比如原来的rowkey为rawStr,则需要对其取hashCode,然后进行按照比特位反转后放在最初rowkey串的前面。可以充分利用Bytes这个工具类来做。

public static void main(String[] args) throws Exception {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "hadoop1");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        HConnection connection = HConnectionManager.createConnection(conf);
        HTableInterface table = connection.getTable("huanggang");
        for (int i=1; i< 6553500; i++) {
            byte[] rowKey = Bytes.add(Bytes.toBytes(Integer.reverse(Integer.valueOf(Integer.valueOf(i).hashCode()))), Bytes.toBytes(i));
            System.out.println(rowKey);
            Put put = new Put(rowKey);
            put.add("f".getBytes(), "col1".getBytes(), Bytes.toBytes(new Random().nextInt(10000)));
            put.add("f".getBytes(), "col2".getBytes(), Bytes.toBytes(new Random().nextInt(10000)));
            put.add("f".getBytes(), "col3".getBytes(), Bytes.toBytes(new Random().nextInt(10000)));
            put.add("f".getBytes(), "col4".getBytes(), Bytes.toBytes(new Random().nextInt(10000)));
            put.add("f".getBytes(), "col5".getBytes(), Bytes.toBytes(new Random().nextInt(10000)));
            put.add("f".getBytes(), "col6".getBytes(), Bytes.toBytes(new Random().nextInt(10000)));
            table.put(put);
        }
        table.flushCommits();
        table.close();
    }

建表:

bubuko.com,布布扣


表现:

bubuko.com,布布扣

HBase预分区のUniformSplit

标签:style   blog   http   io   color   ar   os   java   for   

原文地址:http://blog.csdn.net/huanggang028/article/details/40819517

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!