zoukankan      html  css  js  c++  java
  • 用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     }
  • 相关阅读:
    ps去掉png alpha
    unity运行中抓显示中的贴图数量和内存
    再议移动平台的AlphaTest效率问题
    ios ExportOptions.plist
    iOS开发-导出xcode中已有的配置文件Provisioning profile
    iOS命令行自动打包(archive)
    mac sh相关
    在Mac中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory
    mac运行sh
    mac上显示隐藏系统文件的快捷键
  • 原文地址:https://www.cnblogs.com/xuyou551/p/8028351.html
Copyright © 2011-2022 走看看