码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-12-12 17:29:55      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:row   ++   apache   print   log   min   hadoop   创建   out   

 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     }

 

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

标签:row   ++   apache   print   log   min   hadoop   创建   out   

原文地址:http://www.cnblogs.com/xuyou551/p/8028351.html

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