public void createTable(String tableName, List<String> ColumnFamilies) {
    HBaseAdmin admin = null;
    try {
      admin = new HBaseAdmin(conf);
      HTableDescriptor tableDescriptor = new HTableDescriptor(Bytes.toBytes(tableName));

      for (String columnFamily : ColumnFamilies) {
        HColumnDescriptor columnDescriptor = new HColumnDescriptor(columnFamily);
        tableDescriptor.addFamily(columnDescriptor);
      }
      admin.createTable(tableDescriptor);
      admin.close();
    } catch (TableExistsException e) {
      System.out.println("Table already exist:" + tableName);
      try {
        admin.close();
      } catch (IOException e1) {
        System.out.println("Error occurred while cloing the HBaseAdmin conneciton:" + e1);
      }
    } catch (MasterNotRunningException e) {
      throw new RuntimeException("HBase master not running, table creation failed.");
    } catch (ZooKeeperConnectionException e) {
      throw new RuntimeException("Zookeeper not running, table creation failed.");
    } catch (IOException e) {
      throw new RuntimeException("IO error, table creation failed.");
    }
  }
Ejemplo n.º 2
0
 protected void createTable(String tableName) throws Exception {
   HTableDescriptor td = new HTableDescriptor(tableName.getBytes());
   HColumnDescriptor cd = new HColumnDescriptor(TEST_TABLE_CF.getBytes());
   td.addFamily(cd);
   admin.createTable(td);
   LOG.info(tableName + " table is successfully created.");
 }
Ejemplo n.º 3
0
 public void createTable(String tableName, List<String> columnFamilies) {
   try {
     Admin admin = connection.getAdmin();
     HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(tableName));
     for (String family : columnFamilies) {
       descriptor.addFamily(new HColumnDescriptor(family));
     }
     admin.createTable(descriptor);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }