zoukankan      html  css  js  c++  java
  • hbase预分区

    语法

    create 't1', 'f1', SPLITS => ['10', '20', '30', '40']
    create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
    # Optionally pre-split the table into NUMREGIONS, using
    # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
    create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
    create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', REGION_REPLICATION => 2, CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
    

      hbase shell实现

    create 'fei', {NAME =>'f'}, SPLITS => [ '1', '2', '3','4','5','6','7','8','9']

    效果

    scala代码实现

    将hbase-site.xml放到resources目录

    import org.apache.hadoop.conf.Configuration
    import org.apache.hadoop.hbase.client.{ColumnFamilyDescriptorBuilder, ConnectionFactory, TableDescriptorBuilder}
    import org.apache.hadoop.hbase.util.Bytes
    import org.apache.hadoop.hbase.{HBaseConfiguration, TableName}
    
    object HbaseCreate {
      def main(args: Array[String]): Unit = {
        //读取hbase-site.xml的方式创建hbaseConf
        val hbaseConf = HBaseConfiguration.create(new Configuration())
        val connection = ConnectionFactory.createConnection()
        val admin = connection.getAdmin();
        val tableName = TableName.valueOf("afei")
        //如果有表就删除
        if (admin.tableExists(tableName)) {
          admin.disableTable(tableName)
          admin.deleteTable(tableName)
        }
        val tableDescriptor = TableDescriptorBuilder.newBuilder(tableName)
    
        val columnDescBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f"))
        columnDescBuilder.setMaxVersions(3)
    
        tableDescriptor.setColumnFamily(columnDescBuilder.build)
    
        //预分区
        /* val splitKeys = Array( 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"))*/
        var splitKeys: List[Array[Byte]] = List()
        for (x <- 1 to 9) {
          if(x<10){
            splitKeys = splitKeys.+:(Bytes.toBytes(x.toString))
          }else{
            splitKeys = splitKeys.+:(Bytes.toBytes(x.toString))
          }
    
        }
    
        //创建表
        admin.createTable(tableDescriptor.build(), splitKeys.toArray)
    
        admin.close()
        connection.close()
    
        println("创建完成")
      }
    
    }
  • 相关阅读:
    IDEA 使用镜像快速创建SpringBoot项目
    ajax基础学习笔记
    GitHub高效搜索
    MVC收藏的实现
    一个显示界面
    R-MS
    MS-API。AJAS
    MS-MVCAJAS 秒杀的添加功能吧
    真-API控制器AJAS
    真-API.DALBLL.AJAS/// 添加/// 绑定分类/// 显示,查询/// 删除//删除/// 反填/// 修改
  • 原文地址:https://www.cnblogs.com/jottings/p/10109431.html
Copyright © 2011-2022 走看看