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."); } }
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."); }
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(); } }