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("创建完成")
      }
    
    }
  • 相关阅读:
    2018 ACM 网络选拔赛 徐州赛区
    2018 ACM 网络选拔赛 焦作赛区
    2018 ACM 网络选拔赛 沈阳赛区
    poj 2289 网络流 and 二分查找
    poj 2446 二分图最大匹配
    poj 1469 二分图最大匹配
    poj 3249 拓扑排序 and 动态规划
    poj 3687 拓扑排序
    poj 2585 拓扑排序
    poj 1094 拓扑排序
  • 原文地址:https://www.cnblogs.com/jottings/p/10109431.html
Copyright © 2011-2022 走看看