用java代码在创建hbase表时指定region的范围

 1 package com.liveyc.common.utils;
 2 
 3 import java.util.List;
 4 
 5 import org.apache.hadoop.hbase.util.Bytes;
 6 import com.liveyc.datarecover.utils.FileToHbase;
 7 public class NewTable {
 8     public static void main(String[] args) throws Exception {
 9         createTable("20171201","20181201");
10     }
11     public static void createTable(String bDate,String eDate) throws Exception{
12         List<String> dateList = FileToHbase.dateList(bDate, eDate);
13         byte[][] regions = new byte[dateList.size()][];
14         //根据时间段获取region,新建表
15         for(String d : dateList){
16             regions[dateList.indexOf(d)] = Bytes.toBytes(d); 
17         }
18         String[] family = {"Fileinfo","Archiveinfo"};
19         String tableName = "view_store";
20         HbaseUtils.creatTable(tableName,family ,regions);
21     }
22 }
 1  /**
 2      * 创建表
 3      * @param tableName 表名
 4      * @param family 列族
 5      * @param regions region
 6      * @throws Exception
 7      */
 8     public static void creatTable(String tableName, String[] family,byte[][] regions)
 9             throws Exception {
10         HBaseAdmin admin = new HBaseAdmin(conf);
11         HTableDescriptor desc = new HTableDescriptor(tableName);
12         for (int i = 0; i < family.length; i++) {
13             desc.addFamily(new HColumnDescriptor(family[i]));
14         }
15         if (admin.tableExists(tableName)) {
16             System.out.println("table Exists!");
17             //System.exit(0);
18         } else {
19             if(regions != null){
20                 admin.createTable(desc,regions);
21                 System.out.println("create table Success!");
22             }else{
23                 admin.createTable(desc);
24                 System.out.println("create table Success!");
25             }
26             
27            
28         }
29     }

 

转载于:https://www.cnblogs.com/xuyou551/p/8028351.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值